【发布时间】:2011-05-02 22:25:46
【问题描述】:
我加载了一个 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();
此代码返回未定义:
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":"admin@app.com"}]}
我也测试过这段代码:
var records = new Array()
var test = appSettingStore.each(function(rec){
records.push(rec)
})
console.log(records)
我得到一个空数组!
PS : 这个 store 没有绑定任何组件; 我只想读写它。
【问题讨论】:
-
我注意到你会遇到一个问题。在您的 JsonReader 的字段对象中,您声明了一个名为“idProjet”的字段,但您的服务器返回“projetId”。确保这些匹配以获得所需的结果。
-
这是一个错误,问题没有解决,我把商店很好地加载了,我用网格测试过它可以工作!我仍然无法使用 find() 或任何过滤功能
-
出了什么问题,出于好奇?
-
问题是商店加载正常,但我不能使用类似的方法:find()、getById()、getAt()?
标签: javascript json extjs store