EXT JS商店代理:读者和作家 [英] EXT JS Store's Proxy: readers and writers
问题描述
在文档中,我找到了一个这样实例化的商店:
In the documentation, i have found a store instantiated like this:
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
model: "User",
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json',
root: 'users'
}
}
});
代理有一个 url
config。我对读者特别感兴趣读者指定数据交换格式(json)和根('users')。现在,换句话说,如果商店设置为: autoLoad = true
,则EXT JS将使Ajax连接到指定的URL,以便读
。现在,我将如何配置上述同一个商店的作家?有人也告诉我:如果我配置一个作家,它会使用与代理中指定的相同的url吗?我仍然在上面显示的代码的上下文中对作者和读者感到困惑,您可以帮助我使用上面的例子来显示读者和作家配置。谢谢。
The proxy has one url
config. I am particularly interested in the reader. The reader specifies the data exchange format (json) and the root ('users'). Now, in other words if the store is set up to be: autoLoad = true
, then EXT JS will make an Ajax connection to the url specified in order to read
. Now, how would i configure a writer for that same store above? Someone also tell me about this: if i configure a writer, would it use the same url as specified in the proxy? am still confused about writers and readers in context of the code i have showed above, you would help me use the above example to show readers and writer configs. Thank you.
推荐答案
这是一个在我的应用程序中有读者,作家和api的商店的例子:
Here is an example of a store with reader, writer and api in my App:
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');
}
}
});
这篇关于EXT JS商店代理:读者和作家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!