如何告诉商店加载了哪个页面
我有一个绑定到网格的商店。当它被加载时,它有n页。
现在我想显示包含特定值的页面。为了做到这一点,我使用 store.load({params: {'file': 'file33939'}});
(使用“file”是因为网格显示文件列表,但它不相关来提问)。现在我不知道它应该是什么页面。响应如下所示:
{
"files":[{"id":"33939", "name": "file33939"}, /* ... */],
"total": 1000,
"page": 13
}
网格显示正确的数据(真正包含“file33939”的页面)。但是,pagingtoolbar、grid 的 rownumberer 和 store.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要更改加载的页面,您不应使用
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 thepagingtoolbar.move(pageNumber)
. This will update your pagingtoolbar along with the grid and the store and everything remains in sync.我已经找到合适的解决方案。这不是最优雅的解决方案。然而它有效。
在深入研究 sencha 代码后,我发现 pagingtoolbar 和 store.indexOfTotal() 正在使用
record.index
(在我的例子中设置为就像加载第一页一样)。record.index
由函数store.loadRecords
中的存储设置:FIXME 注释不是我的。它在代码中。
理想的解决方案是找到一个在响应到来之后、调用 loadRecords 之前触发的事件,并覆盖处理程序中的
options
。不过我还没有发现这样的事件。但你总是可以覆盖 loadRecords:
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 functionstore.loadRecords
: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: