我正在按照 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/