【发布时间】:2013-12-30 22:28:10
【问题描述】:
我试图在我的导航页面加载后立即选择我的列表视图控件中的第一项。以下代码似乎没有效果。如果我将“selection.set(0)”代码放在按钮单击处理程序中,它会正常工作,但一旦页面加载,它就不会工作,这是我想要的效果。有人有想法么?我一定遗漏了一些非常基本的东西!
HTML
<div id="basicListView"
data-win-control="WinJS.UI.ListView"
data-win-options="{itemDataSource : ex.itemList.dataSource,
itemTemplate: select('#mediumListIconTextTemplate'),
layout : {type: WinJS.UI.ListLayout},
selectionMode: 'single',
tapBehavior: 'directSelect'
}">
</div>
JS
(function () {
"use strict";
var _lv = null;
WinJS.UI.Pages.define("/pages/page2/page2.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) {
// TODO: Initialize the page here.
_lv = document.getElementById("basicListView").winControl;
// This should select the first item in the listview though it seems to have no effect.
_lv.selection.set(0);
},
});
})();
【问题讨论】:
-
ex.itemList.dataSource 在哪里设置?你看到列表被填充了吗?如果是 - 尝试使用 loadingstatechanged 事件并在事件处理程序中设置项目