EXT JS Store的代理:读者和作家

问题描述:

在本文档中,我已经找到实例化一个像这样的店铺:EXT JS Store的代理:读者和作家

 
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吗?我仍然对上面显示的代码中的作者和读者感到困惑,您可以帮助我使用上述示例来显示读者和作者配置。谢谢。

这里是读者,作家和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'); 
     } 
    } 
}); 
+0

“写”不触发事件时自动同步=假。这是预期的行为还是错误? –

+0

修正:因为我正在使用会话,需要使用store.sync()来触发事件 –

其实你是正确的 - 它会使用相同的URL作为读者。

代理服务器是客户端的模型/存储和另一端的服务器代码之间的中介。 读取器用于读取数据,您可以配置格式化,指定根等等。作者负责保存/更新服务器的请求。

检查这篇文章:http://edspencer.net/2011/02/proxies-extjs-4.html