Ext.define('DWP.store.Test', {
extend: 'Ext.data.Store',
fields: [
{name: 'field1'},
{name: 'field2'},
],
proxy: {
type: 'ajax',
url : 'resources/data/load.php',
reader: {
type: 'json',
rootProperty: 'root'
}
},
autoLoad: true,
});
我尝试使用此代码从Json获取数据,但没有工作。我如何从json获取数据?
var json = Ext.encode(Ext.pluck(store.data.items, 'store'));
答案 0 :(得分:2)
由于你有autoLoad: true
,这应该是:
var store = Ext.getStore('DWP.store.Test');
store.each(function (record, id) {
console.log(record.get('field1'));
});
如果您更喜欢autoLoad: false
,请执行以下操作:
var store = Ext.getStore('DWP.store.Test');
store.load({
callback: function (records, operation, success) {
store.each(function (record, id) {
console.log(record.get('field1'));
});
}
});