2013-05-27 37 views
0

我有这样一个简单的问题,但无法找到答案(文档)。我创建了Grid,其中信息从MySQL数据库中检索。使用Ext JS 4.2。 让我们来看看脚本...动态编辑数据(网格json Ext JS 4)

Ext.define("AppStore",{ 
    extend: "Ext.data.Model", 
    fields: [ 
     {name: "nickname" , type: "auto"}, 
     {name: "email" , type: "auto"} 
    ] 
}); 

var store = Ext.create("Ext.data.Store",{ 
    model: "AppStore", 
    proxy: { 
     type: "ajax", 
     api: { 
      read : "./read.php", 
      update : "./update.php" 
     }, 
     reader: { 
      type: "json", 
      root: "" 
     }, 
     writer: { 
      type: "json", 
      writeAllFields: true, 
      encode: false, 
      root: "" 
     } 
    }, 
    listeners: { 
     read: function(operation, callback, scope){ 

     }, 
     update: function(operation, callback, scope){ 
      // Do I have to do something from here ? 
     } 
    }, 
    autoLoad: true 
}); 

Ext.create("Ext.grid.Panel",{ 
    store: store, 
    selMode: "cellmodel", 
    columns: [ 
     { 
      text: "Nickname", 
      flex: 1, 
      dataIndex: "nickname", 
      editor: { 
       xtype: "textfield", 
       allowBlank: false 
      } 
     }, 
     { 
      text: "Email", 
      flex: 1.5, 
      dataIndex: "email", 
      editor: { 
       xtype: "textfield", 
       allowBlank: false 
      } 
     } 
    ], 
    plugins: [ 
     Ext.create("Ext.grid.plugin.CellEditing",{ 
      clicksToEdit: 2 
     }) 
    ] 
}); 

一切正常,只是兴趣我怎么也得送请求MySQL的在网格小区改变之后更新数据。任何例子,文件或如何完成这项任务的方式将不胜感激,谢谢...

回答

1

通常,你会想要在你的网格商店打电话sync()为了坚持模型的变化到服务器。这可以配置为在每次编辑时自动发生(请参阅商店的autoSync property)。不过,我建议最好是根据某些特定操作(例如,单击“保存”按钮等)来处理sync()调用。

+0

所以'sync()'请求会发送到这里'update:“./update.php”'是吗?如果在这种情况下是什么将传递参数名称来处理它在PHP端? – tnanoba

+0

是的,这是正确的。当您在商店中调用sync()时,它会将所有待处理的创建/更新/删除请求一起进行批处理。根据您的代理的配置,您的代理将动态地为请求构建正确的URL。关于参数,它将发送模型中标记为持久性(默认值为true)和任何已更改(取决于writeAllFields配置)的任何字段。 – existdissolve