javascript - ListView不显示数据

标签 javascript windows-8 expression-blend windows-store-apps

我正在按照 Building Windows 8 Apps with JavaScript 开头的教程进行操作。我的 ListView 根本不显示数据,我不知道该转向哪里。看起来很简单,很容易,但我一定错过了一些东西。当我运行应用程序(或在 Blend 中查看它)时,我看到了除 ListView 数据之外的所有内容。知道我错过了什么吗?

这是结果:

enter image description here

这是 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/

相关文章:

javascript - 如果选中其他复选框,则禁用复选框

javascript - 为什么这个函数不修改最终输出?

javascript - 更改网页中的鼠标指针

javascript - 错误未捕获语法错误 : Invalid regular expression:/(/: Unterminated group

visual-studio - 仅使用 Visual Studio 进行 Silverlight 2 开发?

mvvm - 如何在 MVVM 应用程序中进行 View/ViewModel 绑定(bind),以便可以使用 Expression Blend?

wpf - MVVM 将 EventArgs 作为命令参数传递

c# - 媒体引擎错误,在本地机器上听不到声音

c# - Listview win8 xaml如何创建列?

javascript - ZXing 的 WinJS 内存不足问题