问题描述
这就是我所拥有的(一些细节可能无关紧要,我不确定):
Here's what I have (some of the details might be irrelevant, I'm not sure):
* 3 WinJS(2.0)页面控件,意味着自定义所有显示在一个页面中的控件:
- 页面控件#1包含一些HTML元素(div,按钮)
- 页面控件#2-3每个包含一个ListView控件。列表视图的itemDataSource在页面控件的js文件中设置,在"ready"中。功能。
* 3 WinJS (2.0) page controls, meant to be custom controls that are all displayed in one page:
- Page control #1 contains some HTML elements (divs, buttons)
- Page controls #2-3 each contain a ListView control. The itemDataSource for the list view is set on the js file of the page control, in the "ready" function.
*包含HTML的主页,如下所示:
< body>
< div>
< div id =" header">
<! - 页面控制1 instatiation - >
< / div>
< div id =" contentSection">
<! - 页面控制2 instatiation - >&
<! - 页面控制3 instatiation - >
< / div>
< / div>
< / body>
* A main page with HTML that looks like this:
<body>
<div>
<div id="header">
<!-- page control 1 instatiation -->
</div>
<div id="contentSection">
<!-- page control 2 instatiation -->
<!-- page control 3 instatiation -->
</div>
</div>
</body>
当我运行应用程序时,我希望看到每个控件的UI。然而,发生了一些奇怪的事情:
*我总是看到控制1,从不看控制2,每10次运行一次,我看到控制3.左边b $ b *如果我只注释掉控制1,我总是看到控制3但从来没有2.
*如果我注释掉控制1和另一个控件,我看到剩下的另一个控件。
When I run the app I expect ofcourse to see the UI of every control. However, something strange happens:
* I always see control 1, never see control 2 and about once every 10 runs I see control 3.
* If I comment out only control 1, I always see control 3 but never 2.
* If I comment out control 1 and another control, I see the other control that is left.
在查看DOM Explorer之后,我发现没有看到控件意味着ListView在DOM中,但项目不在。
After looking at the DOM Explorer I found out that not seeing a control means that the ListView is in the DOM but the items are not.
在Blend中预览页面时,我总是看到控件1和3但不是2。
When previewing the page in Blend, I always see controls 1 and 3 but not 2.
查看组件2的唯一方法是取消注释1和3.
The only way to see component 2 is to uncomment 1 and 3.
我发现的另一件事是如果我延迟分配ListView的itemDataSource(在"ready"函数中),使用setTimeout,即使是1或有时甚至0毫秒,一切都会解决,我可以完美地看到所有3个控件。
Another thing I discovered is that if I delay the assigment of the a ListView's itemDataSource (in the "ready" function), using setTimeout, even by 1 or sometimes even 0 milliseconds, everything is solved and I can see all 3 controls perfectly.
我希望我的描述足够清楚。
I hope my description was clear enough.
任何可能导致此类行为的想法?
Any ideas what might cause such behavior?
推荐答案
这篇关于ListView绑定仅在延迟项目数据源分配时起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!