1

我正在使用 Struts 2 并希望包含一个可编辑的服务器端分页和排序网格。

我需要对 QueryReadStore 进行子类化以实现写入和通知 API。我不想包含服务器端 REST 服务,所以我不想使用 JsonRest 存储。知道如何做到这一点。?我必须重写哪些方法以及如何重写。我已经经历了很多例子,但我不知道如何准确地做到这一点。

也可以只扩展 ItemFileWriteStore 并覆盖其方法以包括服务器端分页吗?如果是这样,那么我需要覆盖哪些方法。我可以举一个关于如何做到这一点的例子吗?

4

1 回答 1

1

答案是 ofc 是的 :) 但是你真的需要继承 ItemFileWriteStore,它不符合你的需要吗?.save() 的简短说明如下。

客户端确实在商店中修改/新建/删除,然后这些项目被标记为脏。当有脏物品时,商店将保留对那些在有的物品的引用,如下所示:

store._pending = { _deletedItems: [], _modifiedItems: [], _newItems: [] };

在调用 save() 时,每个都应该循环,向服务器发送请求但是,如果 _saveEverything 或 _saveCustom 都没有定义,则不会发生这种情况。WriteStore 只需重置其客户端还原功能并保存在客户端内存中。 见源搜索“保存:功能”

这是我的一个简单 writeAPI 的实现,必须修改才能在没有内置验证的情况下使用: OoCmS._storeAPI

简而言之,请遵循这个锅炉,因为您将在服务器上有一个 CRUD 模式:

new ItemFileWriteStore( {
    url: 'path/to/c**R**ud',
    _saveCustom: function() {
        for(var i in this._pending._newItems) if(this._pending._deletedItems.hasOwnProperty(i)) {
          item = this._getItemByIdentity(i);
          dxhr.post({ url: 'path/to/**C**rud', contents: { id:i }});
        }

        for(i in this._pending._modifiedItems) if(this._pending._deletedItems.hasOwnProperty(i)) {
          item = this._getItemByIdentity(i);
          dxhr.post({ url: 'path/to/cr**U**d', contents: { id:i }});
        }

        for(i in this._pending._deletedItems) if(this._pending._deletedItems.hasOwnProperty(i)) {
          item = this._getItemByIdentity(i);
          dxhr.post({ url: 'path/to/cru**D**', contents: { id:i }});
    }
});

现在; 至于分页,ItemFileWriteStore 从它的超类 mixins 中有分页。你只需要用两种设置调用它,一个直接在存储上意味着服务器应该只返回一个子集 - 或者在具有查询能力的模型上服务器返回一个全套。

var pageSize = 5,    // lets say 5 items pr request
    currentPage = 2; // note, starting on second page (with *one* being offset)
store.fetch({
  onComplete: function(itemsReceived) { },
  query: { foo: 'bar*' },               // optional filtering, server gets json urlencoded
  count: pageSize,                      // server gets &count=pageSize
  start: currentPage*pageSize-pageSize  // server gets &start=offsetCalculation
});

quod erat 示范

于 2012-04-29T02:54:09.717 回答