Muz*_*hua 4 html javascript jquery extjs extjs4
在文档中,我发现了一个实例化如下的商店:
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
model: "User",
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json',
root: 'users'
}
}
});
代理有一个url配置.我对读者特别感兴趣.阅读器指定数据交换格式(json)和根('用户').现在,换句话说,如果存储设置为:autoLoad = true,那么EXT JS将与指定的URL建立Ajax连接read.现在,我如何为上面的同一个商店配置一个作家?有人还告诉我这个:如果我配置一个编写器,它会使用代理中指定的相同URL吗?我仍然对上面显示的代码的上下文中的作者和读者感到困惑,你会帮助我使用上面的例子来展示读者和作者的配置.谢谢.
dbr*_*rin 10
这是我的应用程序中带有reader,writer和api的商店的示例:
Ext.define('MyApp.store.Tasks', {
extend: 'Ext.data.Store',
model: 'MyApp.model.Task',
sorters : [{
property: 'idx',
direction: 'ASC'
}],
autoSync:true,
proxy:{
type: 'ajax',
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json',
writeAllFields : false, //just send changed fields
allowSingle :false //always wrap in an array
// nameProperty: 'mapping'
},
api: {
// read:
create: 'task/bulkCreate.json',
update: 'task/bulkUpdate.json'
// destroy:
}
},
listeners : {
write: function(store, operation, opts){
console.log('wrote!');
//workaround to sync up store records with just completed operation
Ext.each(operation.records, function(record){
if (record.dirty) {
record.commit();
}
});
},
update:function(){
console.log('tasks store updated');
}
}
});
Run Code Online (Sandbox Code Playgroud)