带有 dojo、dgrid、TabContainer 和 JsonRest 的 DOMException
这让我疯狂了一个周末,虽然我找到了一个似乎可行的解决方案,但我的问题是,使用 Dojo/Dijit 是否有一些基本的东西是我所遗漏的。
问题是:每当我创建一个页面,其中 dgrid 使用 JsonRest 存储并且位于隐藏选项卡中一个 TabContainer(不是最初选择的一个),我得到 DOMExceptions 和一个有点搞砸的 dgrid。特别是,dgrid 在最后一行数据下方有很大的空白空间,滚动到 dgrid 数据的底部或顶部会引发额外的 DOMException。
如果我单击其中一个列标题对 dgrid 进行排序,它会重置其布局并正常工作。如果 dgrid 在页面的可见部分而不是未选择的选项卡上初始化,那就没问题。如果我使用内存存储而不是 JsonRest,一切都很好(即使 dgrid 是在隐藏选项卡中初始化的)。如果 dgrid 在隐藏选项卡中初始化但没有存储,则可以(但为空)。
根据证据,我猜测问题与 JsonRest 查询需要时间有关,并且由于某种原因,它在初始化时破坏了 dgrid。我的解决方案是创建没有商店的 dgrid,然后在显示包含 dgrid 的选项卡时设置商店。不过,这看起来很笨拙。我应该能够创建一个带有商店的 dgrid,而不必在外部摆弄它。
那么,我的有点 hack 式的解决方案是处理使用服务器提供的数据初始化隐藏 dgrid 的正确(或至少是合理的)方法,还是我缺少 TabContainer+dgrid+JsonRest 的设置?
This drove me crazy for a weekend, and although I found what seems to be a workable solution, my question is whether there is something fundamental about using Dojo/Dijit that I'm missing.
Here's the problem: Whenever I create page in which a dgrid uses a JsonRest store and is in a hidden tab of a TabContainer (one that is not the initially selected one), I get DOMExceptions and a somewhat screwed up dgrid. In particular, the dgrid has a large empty space under the last row of data, and scrolling to the bottom or top of the dgrid's data throws additional DOMExceptions.
If I click on one of the column headers to sort the dgrid, it resets its layout and works fine. If the dgrid initializes on a visible part of the page instead of an unselected tab, it's fine. If I use a Memory store instead of a JsonRest, everything's fine (even if the dgrid is initialized in a hidden tab). If the dgrid is initialized in a hidden tab but without a store, it's fine (but empty).
Based on the evidence, I guessed the problem had something to do with the fact that a JsonRest query takes time, and for some reason that's breaking dgrid when it's initializing. My solution was to create the dgrid without a store, and then set the store when its the tab containing the dgrid was shown. This seems kludgy, though. I should be able to create a dgrid with a store and not have to fiddle with it externally.
So, is my somewhat hack-ish solution the proper (or at least a reasonable) way to handle initializing a hidden dgrid with server-supplied data, or is there something about the setup of TabContainer+dgrid+JsonRest that I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有回答你的问题,但是 Dijit 小部件和容器之间有一个关于小部件的生命周期和启动的合同......特别是,当元素添加到 DOM 时,以及最后,当调用
startup()
方法来布局元素并调整元素大小。 dgrid 可能不参与。也许您可以将某些内容连接到 TabContainer 的启动方法,这将触发 dgrid 组件的布局?I don't have an answer to your question, but there is a contract between Dijit widgets and containers regarding the lifecycle and startup of a widget... in particular, when the elements are added to the DOM and, at the end, when the
startup()
method is called to layout and resize the elements. dgrid probably does not participate. Perhaps you can connect something to the TabContainer's startup method which will trigger a layout of the dgrid component?