如何告诉商店加载了哪个页面

发布于 2024-12-06 00:45:36 字数 503 浏览 2 评论 0原文

我有一个绑定到网格的商店。当它被加载时,它有n页。

现在我想显示包含特定值的页面。为了做到这一点,我使用 store.load({params: {'file': 'file33939'}}); (使用“file”是因为网格显示文件列表,但它不相关来提问)。现在我不知道它应该是什么页面。响应如下所示:

{
  "files":[{"id":"33939", "name": "file33939"}, /* ... */],
  "total": 1000,
  "page": 13
}

网格显示正确的数据(真正包含“file33939”的页面)。但是,pagingtoolbargrid 的 rownumbererstore.indexOfTotal() 的行为就像加载了第一页(而不是第 13 页)。

我如何“告诉”商店商店刚刚加载的页面是 13?

I have a store that is binded to grid. When it is loaded it has n pages.

Now I want to show the page that contains certain value. In order to do that I use store.load({params: {'file': 'file33939'}}); (the 'file' is used because grid shows list of files, but it's irrelevant to question). At this moment I don't know what the page it should be. The response looks like:

{
  "files":[{"id":"33939", "name": "file33939"}, /* ... */],
  "total": 1000,
  "page": 13
}

Grid displays correct data (the page that really contains 'file33939'). However pagingtoolbar, grid's rownumberer and store.indexOfTotal() behave as if the first page was loaded (instead of 13).

How can I "tell" store that the page that store just had loaded is 13?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她比我温柔 2024-12-13 00:45:36

要更改加载的页面,您不应使用store.load()。您应该找到一种方法来获取给定数据的页码(例如,通过 ajax 请求询问服务器),然后通过 pagingtoolbar.move(pageNumber) 更新页面。这将更新您的分页工具栏以及网格和商店,并且所有内容都保持同步。

To change the loaded page you should not use store.load(). You should find a way to get the page number for the given data (e.g. asking the server via an ajax request) and then update the page via the pagingtoolbar.move(pageNumber). This will update your pagingtoolbar along with the grid and the store and everything remains in sync.

○闲身 2024-12-13 00:45:36

我已经找到合适的解决方案。这不是最优雅的解决方案。然而它有效。

在深入研究 sencha 代码后,我发现 pagingtoolbarstore.indexOfTotal() 正在使用 record.index (在我的例子中设置为就像加载第一页一样)。 record.index 由函数 store.loadRecords 中的存储设置:

loadRecords: function(records, options) {
    // ...
    //FIXME: this is not a good solution. Ed Spencer is totally responsible for this and should be forced to fix it immediately.
    for (; i < length; i++) {
        if (options.start !== undefined) {
            records[i].index = options.start + i;

        }
    // ...
},

FIXME 注释不是我的。它在代码中。

理想的解决方案是找到一个在响应到来之后、调用 loadRecords 之前触发的事件,并覆盖处理程序中的 options 。不过我还没有发现这样的事件。

但你总是可以覆盖 loadRecords:

Ext.define('MyApp.store.MyStore', {
    extend          : 'Ext.data.Store',
    // ...
    loadRecords     : function(records, options) {
        if (this.proxy.reader.rawData.page) {
            var page = this.proxy.reader.rawData.page;

            // This is for pagingtoolbar
            this.currentPage = page;

            // The following is for rownumberer and correct index behaviour
            options.page = page;
            options.start = (page-1)*options.limit;
        }
        this.callParent(arguments);
    },
    // ...
});

I've found suitable solution. It's not the most elegant solution. However it works.

After digging in sencha code I've found that pagingtoolbar and store.indexOfTotal() were using record.index (which in my case was set as if the first page was loaded). record.index is set by store in function store.loadRecords:

loadRecords: function(records, options) {
    // ...
    //FIXME: this is not a good solution. Ed Spencer is totally responsible for this and should be forced to fix it immediately.
    for (; i < length; i++) {
        if (options.start !== undefined) {
            records[i].index = options.start + i;

        }
    // ...
},

The FIXME comment is not mine. It was in the code.

The ideal solution would be to find an event which is being fired after the response came and before the loadRecords was called and override options in the handler. However I haven't found such event.

But you always can override loadRecords:

Ext.define('MyApp.store.MyStore', {
    extend          : 'Ext.data.Store',
    // ...
    loadRecords     : function(records, options) {
        if (this.proxy.reader.rawData.page) {
            var page = this.proxy.reader.rawData.page;

            // This is for pagingtoolbar
            this.currentPage = page;

            // The following is for rownumberer and correct index behaviour
            options.page = page;
            options.start = (page-1)*options.limit;
        }
        this.callParent(arguments);
    },
    // ...
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文