Extjs 如何从Ext.data.Store获取值?
这是我的密码Extjs 如何从Ext.data.Store获取值?,extjs,Extjs,这是我的密码 var store = { user_store: new Ext.data.Store({ autoLoad: false, proxy: new Ext.data.HttpProxy({ url: 'a/b/c', }), remoteSort: true, baseParams: { }, reader: new Ext.data.
var store = {
user_store: new Ext.data.Store({
autoLoad: false,
proxy: new Ext.data.HttpProxy({
url: 'a/b/c',
}),
remoteSort: true,
baseParams: {
},
reader: new Ext.data.JsonReader({
totalProperty: 'total',
root: 'root',
fields: ['roles']
})
})
};
store.user_store.load();
这是我的json
{"roles":"2"}
我想问问。如何获取角色的值为“2”
(PS:对不起,我的英语不是很好。)如果响应中只有一项,您可以向load方法添加回调函数:
var store = {
user_store: new Ext.data.Store({
autoLoad: false,
proxy: new Ext.data.HttpProxy({
url: 'a/b/c',
}),
remoteSort: true,
baseParams: {
},
reader: new Ext.data.JsonReader({
totalProperty: 'total',
root: 'root',
fields: ['roles']
})
})
};
store.user_store.load(function(){
this.getAt(0).get('roles')
});
如果响应由以下几项组成:[{“角色”:“2”},{“角色”:“1”}]
您可以迭代存储以检索所有值
store.user_store.load(function(){
this.each(function(record){
var roles = record.get('roles');
// Do stuff with value
});
});
我使用store.first().get('roles'),但TypeError:store.user\u store.first不是函数为什么?.first()不包含在3.4中。请改为尝试store.getAt(0)。它不起作用。我试图解决我的问题。也许我的问题是“真正的问题”。因为方法加载是异步的。我想我应该在load方法中使用callback()。是的,应该在加载存储时尝试获取该值。我已经更新了答案。carcel这个答案对我很有帮助。谢谢