PDA

View Full Version : How to serialize ExtJs object?



nothing
5 Jul 2012, 11:33 PM
How do I serialize an ExtJs object like a container?




var oContainer = Ext.create( 'Ext.container.Container', {
layout : 'fit'
,width : oWindowDiv.getWidth()
,renderTo : oWindowDiv
,autoRender: true
,stateful: true
,stateId: 'stateContainerMain'
}
);

var instances = { };
instances[strInstanceId] = { container: oContainer };
// OR instances[strInstanceId].container = oContainer;
// AND instances[strInstanceId].plugin will contain a DeftJs object
// AND instances[strInstanceId].instanceid will contain the instance id
// ...



Using either "instances" or "instances[strInstanceId].container" as parameter, these functions fail:

JSON.stringify() leads to Uncaught TypeError: Converting circular structure to JSON

Ext.encode() leads to "Uncaught RangeError: Maximum call stack size exceeded"

How to do this?

sdt6585
6 Jul 2012, 11:46 AM
Why do you need to do this? Are you trying to save state between page loads/sessions? I think that it's likely impossible to serialize a java script object that contains circular references like ExtJS components do. Another approach would be to write some code to store the state of all the stores/models, then store the initial config properties of all the objects along with their types. You would have to work out a format for storing it all along with a method for recursively serializing all a containers sub-items. When you go to recreate it all, you would have to start at the bottom of the list and create the sub-items before their containers and I imagine there would be a few exceptions to complicate that approach. Just my two cents though, good luck.

nothing
12 Jul 2012, 6:42 AM
Ok i have given up on this.