简体   繁体   English

dojox gfx从json获取sgv后使节点可移动

[英]dojox gfx make a node moveable after getting sgv from json

I have a surface with some shapes. 我的表面有些形状。 I use 我用

dojox.gfx.utils.toJson(surface)

to generate a json from it, and then 从中生成一个json,然后

dojox.gfx.utils.fromJson(surface, json)

to get the data and append it to the surface. 获取数据并将其附加到表面。 The problem comes when I create a moveable node. 当我创建一个可移动节点时,问题就来了。 After saving it to json and then appending it to the surface, the node is no longer moveable. 将其保存到json,然后将其附加到表面后,该节点将不再可移动。 I found no way of making the node moveable again. 我找不到使节点再次可移动的方法。 Is there a way to do this? 有没有办法做到这一点? I want to be able to save and load svg data in my page and after load, move the elements around. 我希望能够在页面中保存和加载svg数据,并且在加载后,移动元素。 Using dojo seemed easy enough before i stumbled on this problem. 在我偶然发现此问题之前,使用dojo似乎很容易。 If I can't do this easy, is there a better library I can use, to achieve my goal? 如果我做不到这一点,是否可以使用更好的库来实现我的目标?

Edit: here is the actual code: http://pastebin.com/2qLCTw8B 编辑:这是实际的代码: http : //pastebin.com/2qLCTw8B

I found the answer to my problem. 我找到了解决我问题的方法。

First of all, when you require a dojo module it is good to assign it to a variable, which i didn't know. 首先,当您需要一个dojo模块时,最好将其分配给一个我不知道的变量。 This way when assigning the on module, you can use the on function, used to add event listener, anywhere in the code. 这样,在分配on模块时,可以在代码中的任何位置使用on函数,该函数用于添加事件侦听器。 From there it is easy to create a moveable node, when you click on it. 当您单击它时,可从此处轻松创建可移动节点。

It seemed though that this is a useless operation, as you could just iterate over the surface - children array, and make every node moveable. 但这似乎是无用的操作,因为您可以遍历整个表面-子数组,并使每个节点都可移动。

Here is the improved code: http://pastebin.com/wAvSnZpN 这是经过改进的代码: http : //pastebin.com/wAvSnZpN

The code needed, if you decide to use events anyway: 如果您仍然决定使用事件,则需要使用以下代码:

function HandleMouseDown(e) {
    var foo = new dojox.gfx.Moveable(e.gfxTarget);
}

on(surface, 'mousedown', HandleMouseDown);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM