PDA

View Full Version : what's the type of 'records' in callback(records,option,success) in json store.load



Baron89
25 Oct 2012, 10:26 PM
Hi all,i tried to use the data(records) returned from the server,but dont know what type of the data is,my code is like below .seems it's an array,but i just cant use the its elements.


xxx.store.load(//json store {
callback: function(records, options, success){
this.reader.jsonData.groups.group1;//i can call it like this
records.groups;//doesnt work
records[0];//[object Object]
records[0].group1;//undefined
records.length==6//
} });

data from server


{
"groups" : {
"group1" : "Week33",
"group2" : "Week34",
"group3" : "Week35",
"group4" : "Week36",
},
"rows": [ { "data1":"data" } ],
"success" : true,
"metaData" : null,
"cacheName" : "",
"totalRowCount" : 6
}

sword-it
25 Oct 2012, 11:16 PM
Hi,

you can see this link :1. http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.Store-event-load
2 (http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.Store-event-load).http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.Store-method-load

Baron89
28 Oct 2012, 5:14 PM
Hi Sword,do you know why i get the error ' records.get is not a function ' when i try to use the function that belongs to Ext.data.Record?

sword-it
29 Oct 2012, 10:08 PM
Hi,

you can try this:




for(var i=0; i< records.length;i++){
records[i].get('propertyname');
}

Baron89
29 Oct 2012, 10:35 PM
Hi Sword,the function 'get' works now according to what u said.but still cant get the data.
like


records[0].get('groups') ;//undefined

sword-it
29 Oct 2012, 11:25 PM
Hi,

you can use like this one:




records[0].get('group1')

Baron89
30 Oct 2012, 12:00 AM
Hi,

you can use like this one:




records[0].get('group1')


Hi?I finally get the data like below
record[0].get('data1')
let me show you my store code


var WorkOrderRecord = Ext.data.Record.create([
{name: 'data1'} ]);
myStore = Ext.extend(Ext.ux.MultiGroupingStore, {
constructor: function(cfg) {
cfg = cfg || {};
myStore.superclass.constructor.call(this, Ext.apply({

proxy: new Ext.data.HttpProxy({
method: 'POST',
url: '**/test.json'
}),
autoLoad: false,

reader: new Ext.data.JsonReader({
root: 'rows',
successProperty: 'success',
messageProperty: 'message',
totalProperty: 'total',

},
WorkOrderRecord
)
}));
}
});

willigogs
30 Oct 2012, 1:17 AM
Providing your root config in the beginning would've helped ;)

I really would recommend using Firebug and the console.log() function, since this would've helped you to see exactly what type of object records was, and what the child names are.

Baron89
30 Oct 2012, 2:49 AM
Hey buddy,how to use firebug to see the child names of records?

willigogs
30 Oct 2012, 3:03 AM
console.log(records)

https://getfirebug.com/logging

Baron89
30 Oct 2012, 5:01 PM
Hey buddy,thx alot, console.log() is quite useful:D

willigogs
31 Oct 2012, 3:31 AM
You might also want to download illuminations for firebug:
http://www.illuminations-for-developers.com/

(http://www.illuminations-for-developers.com/)This allows you to console.log() ext components (i.e. stores, gridpanels, etc), and be able to view the records within, all attributes and properties, etc, as you would normally navigate an element's DOM tree. It's invaluable for when debugging with EXTJS.