在html(metro应用程序)中嵌套WinJS.UI.Listviews

时间:2012-07-06 12:51:52

标签: windows-8 microsoft-metro winjs

以下是html:

<div class="itemtemplate" data-win-control="WinJS.Binding.Template">
    <h4 class="title" data-win-bind="textContent: title"></h4>
    <div class="list" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none' }"></div>
</div>


<div class="groupeditemslist" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none' }"></div>

如何在完整的html中添加data-win-options(没有嵌套WinJS.UI.ListView的javascript templateSelector,如“Metro: Dynamically Switching Templates with a WinJS ListView”来绑定数据?

对于主要数据中的每个项目,我添加了WinJS.Binding.List

1 个答案:

答案 0 :(得分:0)

假设您的数据格式为:

var firstLevelDataSource = new WinJS.Binding.List(
    [{title: "t1", secondLevelBinding: new WinJS.Binding.List([1])},
     {title: "t2", secondLevelBinding: new WinJS.Binding.List([2])}]);

// then you expose firstLevelDataSource as Data.firstLevelDataSource

然后,这不会起作用吗?

<div class="itemtemplate" data-win-control="WinJS.Binding.Template">
    <h4 class="title" data-win-bind="textContent: title"></h4>
    <div class="list" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none', itemDataSource: secondLevelBinding.dataSource }"></div>
</div>

<div class="groupeditemslist" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none', itemDataSource: Data.firstLevelDataSource.dataSource }"></div>