在日常使用store获取远程数据时,经常遇到需要远程接口返回的数据并不是直接就是前端需要的,或者希望在返回store数据的同时,返回其他相关数据,此时可以在store获取返回值时直接在store内部针对数据进行一次处理。
在配置reader时支持transform可传递一个方法,方法返回值为实际写入store的数据。
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
transform: {
fn: function(data) {
// do some manipulation of the raw data object
return data;
},
scope: this
}
}
},
autoLoad: true
});
浙公网安备 33010602011771号