3

我正在尝试创建一个网格,该网格在 Ext JS 4.0.7 中有一个带有 PagingMemoryProxy 的商店。我希望能够编辑商店中的信息,但我发现如果我编辑信息并转到下一页,我会丢失前一页上编辑的信息。我的代码如下。

Ext.Loader.setConfig({
  enabled: true
});

Ext.Loader.setPath('Ext.ux', 'examples/ux');

Ext.require('Ext.ux.data.PagingMemoryProxy');

Ext.onReady(function() {
  var data = [
    {name: 'jack johnson', text: 'record1'},
    {name: 'jack johnson', text: 'record2'},
    {name: 'jack johnson', text: 'record3'},
    {name: 'jack johnson', text: 'record4'}
  ];

  var store = Ext.create('Ext.data.Store', {
    fields: ['name', 'text'],
    data: data,
    proxy: {
      type: 'pagingmemory'
    },
    pageSize: 2
  });

  var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    region: 'center',
    id: 'thegrid',
    plugins: [{
      ptype: 'cellediting',
      clicksToEdit: 1,
      listeners: {
        edit: function(editor, e) {
          //e.record.commit();
        }
      }
    }],
    columns: [{
      text: 'Name',
      dataIndex: 'name',
      editor: {
        allowBlank: false
      }
    }, {
      text: 'Text',
      dataIndex: 'text'
    }],
    dockedItems: [{
      xtype: 'pagingtoolbar',
      store: store,
      dock: 'bottom',
      displayInfo: true
    }],
  });

  Ext.create('Ext.Viewport', {
    layout: 'border',
    items: [grid]
  });
});

我想知道如何将商店的数据与代理的数据同步,因为商店的数据实际上包含记录,而代理的数据包含记录的数据,因此无法在代理中通过 id 找到记录。我决定尝试一下同步方法。

使用同步方法后,似乎什么也没发生,所以我想也许我应该提交记录......因此注释掉的e.record.commit代码。当那没有做任何事情时,我开始在 Firebug 中进行挖掘,最终在 ext-all-debugme.getNewRecords代码中看到了第 44,600 行。这最终导致我只返回未提交的记录(因为它显然检查了记录的幻像属性),因此,我编辑的任何记录都不会包含在第toCreate44,600 行的变量中。

当我取出 e.record.commit 时,toCreate 变量现在包含已编辑的记录,但这些都没有帮助解决我的问题......只是最初的探索和我发现的内容。

所以我的问题是,如何将存储与 PagingMemoryProxy 同步?是否可以?如果是这样,我该怎么办?

任何帮助,将不胜感激!

4

1 回答 1

1

Solved the problem by looping through the JSON data that I eventually add to the PagingMemoryProxy... basically added an "index" value to each record in the JSON, so when I want to edit the record in the store, I can easily index into its PagingMemoryProxy by using this index value. Simple fix.

于 2012-07-20T00:45:24.453 回答