我有一个json存储加载,我需要从中获取一条记录.
我用过:getAt(index),find(),getById(),但没有结果.
这是我的代码:
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();
此代码返回undefined:
console.log(appSettingStore.getAt(0));
console.log(appSettingStore.find("id","1"));
这是从服务器返回的json字符串:
{success:true,"results":[{"id":"1","projetId":"1","resLevels":"1","maxResToLock":"40","maxTimetoLock":"10","infosToPrint":"1_2_3_5","hotlineMail":"[email protected]"}]}
我也测试了这段代码:
var records = new Array()
var test = appSettingStore.each(function(rec){
records.push(rec)
})
console.log(records)
我得到一个空数组!
PS:这个商店不受任何组件的约束;
我只想读写它.
解决方法:
您需要在商店上放置一个回调,它将在加载后触发.然后,您可以根据需要使用数据.
store.load({
callback : function(r, options, success) {
console.log(r.data)
}
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。