如何使用带有 ListLayout 的 WinJS.UI.ListView 实现组:
<div id="itemTemplate" data-win-control="WinJS.Binding.Template">
<div data-win-bind="innerText: title"></div>
</div>
<div id="headerTemplate" data-win-control="WinJS.Binding.Template">
<div data-win-bind="innerText: group"></div>
</div>
<div id="menu" data-win-control="WinJS.UI.ListView" data-win-options="{automaticallyLoadPages:false, groupHeaderTemplate:select('#headerTemplate'), groupDataSource:QuickGuide.itemListGrouped.groups.dataSource, itemDataSource:QuickGuide.itemListGrouped.dataSource, itemTemplate:select('#itemTemplate'), layout:{type:WinJS.UI.ListLayout}}">
</div>
JS文件:
function getGroupKey(dataItem) {
return dataItem.group;
}
function getGroupData(dataItem) {
return {
group: dataItem.group
};
}
var dataList = new WinJS.Binding.List(dataArray);
var dataListGrouped = dataList.createGrouped(getGroupKey, getGroupData);
WinJS.Namespace.define("QuickGuide", {
data: dataArray,
itemList: dataList,
itemListGrouped: dataListGrouped
});
它仅适用于 GridLayout,不适用于 ListLayout。