绑定 itemDataSource 来选择 html 元素? [英] Bind itemDataSource to select html element?
本文介绍了绑定 itemDataSource 来选择 html 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将List-Binding绑定到HTML Select()元素上,将绑定的内容显示为元素?
Is it possible to bind a List-Binding to a HTML Select () element to display the contents of the binding as elements?
我现在正在使用它,但似乎不起作用:
Im using this right now, which doesn't seem to work:
<select data-win-options="{itemDataSource: ...)}"></select>
推荐答案
有一种没有声明式绑定的编程方式:
There is a programmatical way without declarative binding:
JavaScript 部分:
JavaScript part:
// Load data
var options = [
{ optionValue: 1, optionText: 'One', selected: false },
{ optionValue: 2, optionText: 'Two', selected: true },
{ optionValue: 3, optionText: 'Three', selected: false }
];
// Fill select box
options.forEach(function (value, i) {
var newOption = document.createElement("option");
newOption.text = value.optionText;
newOption.value = value.optionValue;
if (value.selected) {
newOption.selected = true;
}
myBox.add(newOption);
});
HTML 部分:
<select id="myBox"></select>
否则,您可以使用带有模板的 WinJS.UI.ListView:http://msdn.microsoft.com/en-us/library/windows/apps/br211837.aspx
Otherwise, you can use a WinJS.UI.ListView with a template: http://msdn.microsoft.com/en-us/library/windows/apps/br211837.aspx
这篇关于绑定 itemDataSource 来选择 html 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文