简体   繁体   中英

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

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. 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. Using dojo seemed easy enough before i stumbled on this problem. 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

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. This way when assigning the on module, you can use the on function, used to add event listener, anywhere in the code. 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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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