Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  107] [ 5]  / answers: 1 / hits: 30767  / 14 Years ago, sat, october 30, 2010, 12:00:00

I have a json store loaded, I need to grab one record from it.
I used : getAt(index), find(), getById(), but no results .
This is my code :



var appSettingReader = new Ext.data.JsonReader({     
root: 'results',
},[
{name: 'id', type: 'int', mapping: 'id'},
{name: 'projetId', type: 'int', mapping: 'projetId'},
{name: 'resLevels', type: 'int', mapping: 'resLevels'},
{name: 'maxResToLock', type: 'int', mapping: 'maxResToLock'},
{name: 'maxTimeToLock', type: 'int', mapping: 'maxTimeToLock'},
{name: 'infosToPrint', type: 'string', mapping: 'infosToPrint'}
])

var appSettingStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'inc/getSettings.php',
method: 'POST'
}),
baseParams:{task: app},
reader : appSettingReader,
sortInfo:{field: 'id', direction: DESC}
})

appSettingStore.load();


This code return undefined :



console.log(appSettingStore.getAt(0));

console.log(appSettingStore.find(id,1));


This is the json string returned from server :



{success:true,results:[{id:1,projetId:1,resLevels:1,maxResToLock:40,maxTimeToLock:10,infosToPrint:1_2_3_5,hotlineMail:[email protected]}]}


I've also tested this code :



var records = new Array()       
var test = appSettingStore.each(function(rec){
records.push(rec)
})
console.log(records)


and I get an empty array !



PS : This store is not bound to any component;
I just want to read and write to it.


More From » json

 Answers
51

You need to place a callback on the store, that will be fired after it loads. You can then use the data as required.



store.load({
callback : function(r, options, success) {
console.log(r.data)
}
})

[#95128] Wednesday, October 27, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andreguym

Total Points: 125
Total Questions: 112
Total Answers: 103

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;