View Full Version : Load array into store
jedihua
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
evant
20 Dec 2010, 12:45 PM
"a" is not valid Javascript. It needs to be:
[{
aa: 1,
bb: 2,
cc: 3
}]
jedihua
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
evant
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...
jedihua
20 Dec 2010, 1:01 PM
In your example. It seperates
Col: [aa,bb,cc] data: [1,2,3] and looks like above
jedihua
20 Dec 2010, 1:02 PM
I got confused too. But that's the json object I got from the server side
jedihua
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?
jedihua
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]
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.