View Full Version : Load array into store

20 Dec 2010, 11:57 AM
Hi, I'm having some array to load into a store. For example,

a = [{1, 2, 3}, {2, 3, 4}]; I want to load a into store b, which b is:

b = Ext.data.Store({
model: 'c',
data: a
}) ;

Ext.regModel('c', {fields: ['aa', 'bb', 'cc']});

In the code, The system think the data in a is, title, not the actual data, so 1 2 3 become fields name, and the data is null. Can anyone help me to fix this? Thanks

20 Dec 2010, 12:45 PM
"a" is not valid Javascript. It needs to be:

aa: 1,
bb: 2,
cc: 3

20 Dec 2010, 12:59 PM
Thanks for the reply. That's the data I got from the server. The json object in memory is like

{[225,225,"hi earth"],[265,245,"hello world"]}
format and it's returned by coldfusion. It seperate the field name and data array in the json object, I just dont know how to put it in a datastore. Could you give me some advice? Thanks

20 Dec 2010, 1:00 PM
Again, what you've posted there isn't valid JS, so I don't even know how that would work...

20 Dec 2010, 1:01 PM
In your example. It seperates
Col: [aa,bb,cc] data: [1,2,3] and looks like above

20 Dec 2010, 1:02 PM
I got confused too. But that's the json object I got from the server side

20 Dec 2010, 1:16 PM
I think the format is like this

{"COLUMNS": ["ID", "DATE", "AGE"], "DATA":[[200,"sep 1", 10],[100,"sep 2", 11]]}
Is there anyway I can convert it into a datastore? Or do I have to hard code to do that?

20 Dec 2010, 1:19 PM
if the above code is in variable aa. Then aa.DATA is an array of length 2, with aa.DATA[0] = [200,"sep 1", 10]