ListView绑定仅在延迟项目数据源分配时起作用 [英] ListView binding works only when delaying item datasource assignment

查看:102
本文介绍了ListView绑定仅在延迟项目数据源分配时起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的(一些细节可能无关紧要,我不确定):

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?

推荐答案

我不确定为什么你在一个页面上有多个页面控件;这似乎打破了PageControl API的预期用途(如果这是你在自定义页面控件中使用的那个),我建议尝试在页面上使用带有
多个DIV元素的单个页面控件。在任何情况下,如果setTimeout有效,那么您的HTML或JavaScript代码中可能会有标记,即在数据返回之前调用数据模型。如果是这样,您可以在数据模型中创建
事件而不是使用setTimeout,并在数据可用后向页面添加一个侦听器以设置itemDataSource。 (要查找示例,请搜索"具有异步数据的集线器模板样本"的样本。)

I'm not really sure why you have multiple page controls on one page; that appears to break the intended use of the PageControl API (if that's what you're using in your custom page control), and I'd suggest trying to use a single PageControl with multiple DIV elements on the page. In any case, if setTimeout works then maybe there is markup in your HTML or JavaScript code that is calling the data model before the data has returned. If so, instead of using setTimeout, you could create an event in your data model and add a listener to the page to set the itemDataSource once the data is available. (To find an example, search samples for "Hub template sample with asynchronous data".)


这篇关于ListView绑定仅在延迟项目数据源分配时起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆