Javascript EXT JS商店';s代理人:读者和作者

Javascript EXT JS商店';s代理人:读者和作者,javascript,jquery,html,extjs,extjs4,Javascript,Jquery,Html,Extjs,Extjs4,在文档中,我发现了一个如下实例化的存储: var store = Ext.create('Ext.data.Store', { autoLoad: true, model: "User", proxy: { type: 'ajax', url : 'users.json', reader: { type: 'json', root: 'users' }

在文档中,我发现了一个如下实例化的存储:

var store = Ext.create('Ext.data.Store', { autoLoad: true, model: "User", proxy: { type: 'ajax', url : 'users.json', reader: { type: 'json', root: 'users' } } }); var store=Ext.create('Ext.data.store'{ 自动加载:对, 型号:“用户”, 代理:{ 键入:“ajax”, url:'users.json', 读者:{ 键入:“json”, root:'用户' } } });
代理有一个
url
config。我对读者特别感兴趣。读取器指定数据交换格式(json)和根(“用户”)。现在,换句话说,如果存储设置为:
autoLoad=true
,那么extjs将与指定的url建立Ajax连接,以便
读取
。现在,我如何为上面的同一个存储配置writer?还有人告诉我:如果我配置一个writer,它会使用代理中指定的相同url吗?在我上面展示的代码的上下文中,我仍然对编写器和编写器感到困惑,您可以帮助我使用上面的示例来展示编写器和编写器配置。谢谢。

实际上你是对的-它将使用与reader相同的url

代理是客户机上的模型/存储和另一端的服务器代码之间的中介。 读卡器用于读取数据,您可以配置格式化、指定根目录等内容。写卡器负责向服务器发送保存/更新请求


查看本文:

以下是我的应用程序中包含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');
        }
    }
});

当autosync=false时,不会触发“写入”事件。这是预期的行为还是bug?已修复:当我使用会话时,需要store.sync()来触发事件