我如何在 Win8 应用程序中的 WinJS.Binding.Template 中设置 id [英] How do i set the id in WinJS.Binding.Template in a Win8 App
问题描述
以下 html 对我不起作用.
<span data-win-bind="innerText: name; id: id"></span><div id="basicListView" style="width:420px;height:600px" data-win-options="{ itemTemplate: select('#weightListViewTemplate') }"data-win-control="WinJS.UI.ListView">
列表出现,但没有在 span 对象上设置 ID 属性.
如何根据datasource/array中对应的值在模板中动态设置span的id?
我不建议使用实际的 ID 属性.我相信你不能通过数据绑定来设置它——我相信 WinJS 在幕后使用元素上的 ID 来允许对 DOM 元素的弱引用.因此,它不允许您设置 ID.
我建议改用其他属性或属性.
The following html is not working for me.
<div id="weightListViewTemplate" data-win-control="WinJS.Binding.Template">
<span data-win-bind="innerText: name; id: id"></span>
</div>
<div id="basicListView" style="width:420px;height:600px" data-win-options="{ itemTemplate: select('#weightListViewTemplate') }"
data-win-control="WinJS.UI.ListView">
</div>
The list appears but the ID property is not set on the span objects.
How to a set the id of the span dynamically in the template based on the corresponding value in the datasource/array?
I wouldn't recommend using the actual ID property. I believe you can't set it through data binding -- I believe WinJS uses ID's on elements under the covers to allow for weak-references to the DOM elements. Because of this it doesn't let you set the ID.
I would suggest using another property or attribute instead.
这篇关于我如何在 Win8 应用程序中的 WinJS.Binding.Template 中设置 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!