这是我的代码
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')
});
如果响应包含多个项目,例如:
[{"roles":"2"},{"roles":"1"}]
您可以迭代商店以检索所有值。store.user_store.load(function(){
this.each(function(record){
var roles = record.get('roles');
// Do stuff with value
});
});
关于extjs - 如何从 Ext.data.Store 获取值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13396346/