我正在遵循Building Windows 8 Apps with JavaScript开头的教程。我的ListView只是不显示数据,而且我不确定要转到哪里。看起来很简单,但是我必须缺少一些东西。当我运行该应用程序(或在Blend中查看它)时,除了ListView数据外,我看到的所有内容。知道我缺少什么吗?

结果如下:



这是HTML:

<body>
    <div class="fragment homepage">
        <header aria-label="Header content" role="banner">
            <button class="win-backbutton" aria-label="Back" disabled type="button"></button>
            <h1 class="titlearea win-type-ellipsis">
                <span class="pagetitle">Bob's RSS Reader</span>
            </h1>
        </header>
        <section aria-label="Main content" role="main">
            <div>List of feeds:</div>
            <div data-win-control="WinJS.UI.ListView" data-win-options="{itemDataSource:feeds.dataSource}"></div>
        </section>
    </div>
</body>


这是home.js文件:

(function () {
    "use strict";

    window.feeds = [
        { title: "Brandon Satrom",
            url: "http://feeds.feedburner.com/userinexperience/tYGT" },
        { title: "Chris Sells",
            url: "http://sellsbrothers.com/posts/?format=rss" },
        { title: "Channel 9",
            url: "http://channel9.msdn.com/Feeds/RSS" },
    ];

    WinJS.UI.Pages.define("/pages/home/home.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {

        }
    });
})();

最佳答案

我可以通过使用here指导使其工作。此解决方案创建一个命名空间以使数据公开可用。虽然可以,但是我不明白为什么我的原始代码无法正常工作。我以为window.feeds可以用于HTML ...猜测不行。

HTML:

<div data-win-control="WinJS.UI.ListView" data-win-options="{itemDataSource: DataExample.itemList.dataSource}"></div>


JavaScript:

(function () {
    "use strict";

    var dataArray = [
        { title: "Brandon Satrom",
            url: "http://feeds.feedburner.com/userinexperience/tYGT" },
        { title: "Chris Sells",
            url: "http://sellsbrothers.com/posts/?format=rss" },
        { title: "Channel 9",
            url: "http://channel9.msdn.com/Feeds/RSS" },
    ];

    var dataList = new WinJS.Binding.List(dataArray);

    // Create a namespace to make the data publicly accessible.
    var publicMembers =
    {
        itemList: dataList
    };

    WinJS.Namespace.define("DataExample", publicMembers);

    WinJS.UI.Pages.define("/pages/home/home.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {

        }
    });
})();

关于javascript - ListView不显示数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14531177/

10-12 15:57
查看更多