Bind itemDataSource to select html element?

拥有回忆 提交于 2019-12-11 15:09:43

问题


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>

回答1:


There is a programmatical way without declarative binding:

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 part:

<select id="myBox"></select>

Otherwise, you can use a WinJS.UI.ListView with a template: http://msdn.microsoft.com/en-us/library/windows/apps/br211837.aspx



来源:https://stackoverflow.com/questions/13111064/bind-itemdatasource-to-select-html-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!