QueryReadStore或ItemFileWriteStore子类,以包括写入api和服务器端分页和排序



我使用Struts2,希望包含一个可编辑的服务器端分页和排序网格。

我需要对QueryReadStore进行子类以实现写入和通知API。我不想引入服务器端REST服务,所以我不想使用JsonRest商店。知道怎么做吗。?我必须覆盖哪些方法以及具体如何覆盖。我已经看过很多例子,但我不知道如何做到这一点。

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

答案是:)但你真的需要将ItemFileWriteStore子类化吗?它不符合你的需求吗?下面是.save()的简短解释。

客户端在存储中进行修改/新建/删除,然后这些项被标记为脏项。当有脏东西时,商店会保留对has中那些东西的引用,比如:

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

在调用save()时,应该循环其中的每一个,将请求发送到服务器BUT,如果既没有定义_saveEverything也没有定义_seaveCustom,则不会发生这种情况。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中有来自其超类mixin的分页。。您只需要用两个设置来调用它,一个直接在商店上,这意味着服务器应该只返回一个子集,或者在具有查询能力的模型上,服务器返回一个完整集。

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
});

的验证时间

最新更新