Get records from json store extjs
Solution 1
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)
}
})
Solution 2
It appears the server is returning invalid JSON. Why does your server-side script's output start with "("?
If that's not actually the problem, maybe you should consider accepting some more answers to your questions. People will be more likely to help.
EDIT: Okay, so you're pretty sure you're getting valid json back from the server. Try adding a 'success' property to your server's output.
If that doesn't work, you'll want to dig in a little more. Try adding a callback option to your store's .load(), and look at the stuff that gets passed into the callback. That should help you figure out where things are going wrong.
cranberies
Updated on March 05, 2020Comments
-
cranberies about 4 years
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.
-
cranberies over 13 yearsno its not that the problème , thank you iam waiting for more answers
-
cranberies over 13 yearsthere is no issue in the stor it load fine , i can bind it with a grid i dont know where is the probleme , i cant use store methodes to find records