3

Is it possible to serialize / deserial dojo widget objects?

 3 years ago
source link: https://www.codesd.com/item/is-it-possible-to-serialize-deserial-dojo-widget-objects.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Is it possible to serialize / deserial dojo widget objects?

advertisements

Does anybody know if it is possible to serialize/deserialize dojo widget (dijit) objects to a string or some representation that can be persisted across browser sessions?

My scenario: I have a webpage with various dijits that I would like to be able to take a "snapshot" of and restore in a new browser session so that everything is brought back up in the exact same state. In order to do this I believe I need to serialize/restore the DOM tree of the page as well as the dijit objects. I've been able to serialize the DOM tree and am currently restoring it by replacing the contents of the HTML node of the page. When the page's DOM is restored, none of the dijits work - they are rendered correctly but you can't click any of them. I believe this is because the dojo parser has already run through the DOM when the page first loaded, and replacing the entire HTML DOM element destroys all the dijits in the dijit registry for that page.. which means the dijit classes have to be re-instantiated.

Ideally what I would like to be able to do is when I take a "snapshot", to serialize every dijit object that is contained in the dijit.registry for the page to a file, and when the session is restored, to re-construct those dijit objects and add them back to the dijit registry.

Something like: dijit.registry.forEach(function(widget){ // Save the widget object so that it can be restored in a new browser instance? });

Has anybody tried this or know if it's possible without writing a custom serializer?


I am not sure that I agree with the technique you are using. A better scenario would be to simply serialize the state of the data for each dijit. I know that this would be more work but you are trying to preserve the state of the data, bringing the UI along for the ride seems to be preserving unnecessary information.

That being said, the dojo parser can be called independently of page load. What you are looking for is

dojo.parser.parse();

Running that after you repopulate the innerHTML should re-parse and recreate the dijits See this page for the full reference: http://docs.dojocampus.org/dojo/parser


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK