我正在尝试创建一个新的Windows 8应用程序,我正在尝试实现列表视图。
我目前的问题是document.querySelector('#myListView')。winControl.selection.count();总是返回0 ..当我选择时,取消选择列表视图等。我在listView中手动加载了我的项目,这与它有什么关系吗?
答案 0 :(得分:1)
我们需要在ListView的data-win-option中将selectionMode添加到'multi'
<div id="UserListView" data-win-control="WinJS.UI.ListView" style="border-top: 5px solid #000; min-width:500px;"
data-win-options="{
selectionMode:'multi',
itemTemplate:select('#itemsList'),
layout:{
type:WinJS.UI.GridLayout}}"
>
</div>
然后在js文件中,我们可以将所选列表视图项的计数显示为下面的
var testCount = UserListView.winControl.selection.count();
答案 1 :(得分:0)
你能展示你的代码吗?因为在我的例子中,这个功能正确。 dataExample.js文件中的此代码:
(function () {
"use strict";
var dataArray = [
{ title: "Basic banana", text: "Low-fat frozen yogurt", picture: "images/60banana.png" },
{ title: "Banana blast", text: "Ice cream", picture: "images/60banana.png" },
{ title: "Marvelous mint", text: "Gelato", picture: "images/60mint.png" },
{ title: "Succulent strawberry", text: "Sorbet", picture: "images/60strawberry.png" }
];
var dataList = new WinJS.Binding.List(dataArray);
var publicMembers =
{
itemList: dataList
};
WinJS.Namespace.define("DataExample", publicMembers);
})();
在default.js中我创建了一个函数,它显示了所选项的计数
function someFunc(mouseEvent) {
var count = document.getElementById("basicListView").winControl.selection.count();
var dlg = new Windows.UI.Popups.MessageDialog(count);
dlg.showAsync().operatio;
}
我的default.html包含下一个代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App1</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0/css/ui-white.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
<!-- App1 references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
<script src="/js/dataExample.js"></script>
</head>
<body>
<button id="btn" class="ui-button" onclick="someFunc(event)">click me</button>
<p id="button1Output"></p>
<div id="basicListView" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource : DataExample.itemList.dataSource }">
</div>
</body>
</html>