1

Build 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) {

        }
    });
})();
4

2 に答える 2

1

こちらのガイダンスを使用して動作させることができました。このソリューションは、名前空間を作成してデータを公開します。これは機能しますが、元のコードが機能しなかった理由がわかりません。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) {

        }
    });
})();
于 2013-01-25T23:24:11.393 に答える
0

動作しない理由は、バインディング リストに設定していないためです。通常の JavaScript 配列には、dataSource プロパティが含まれていません。また、'new' キーワードを使用することを忘れないでください。私はそれを忘れて、なぜそれが失敗したのかを理解するのにかなりの時間を費やしました.

window.feeds = new WinJS.Binding.List([
        { 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" },
    ]);
于 2014-02-28T02:22:18.007 に答える