Lin*_*der 5 data-binding jquery optgroup knockout.js drop-down-menu
ELLO,
我已经尝试了所有选项来制作一个带有optgropus的(多个)选择框,并将选项/ selectedOptions与knockout绑定.
selectedOptions绑定似乎存在问题.我的数据似乎是合法的,但它不会显示预选的选项.
我在JSFiddle中做了一个例子:http://jsfiddle.net/aCS7D/251/
<select data-bind="selectedOptions: selectedOptions" multiple="multiple">
<option>Please choose an option</option>
<optgroup data-bind="repeat: groups" data-repeat-bind="attr: {label: $item().label}">
<option data-bind="repeat: $item().children" data-repeat-bind="text: $item().label, option: $item()"></option>
</optgroup>
Run Code Online (Sandbox Code Playgroud)
使用单个选定选项它可以工作,但是有多个选择选项,选择框不能正确渲染它们.
如果任何人有解决这个问题的方法,你将成为我的英雄!
您可以在应用绑定后推送它们,如下所示:
this.selectedOptions = ko.observableArray([]);
//The single selected option
this.selectedOption = ko.observable(selected1);
var vm = new ViewModel()
ko.applyBindings(vm);
var selected1 = vm.groups()[1].children()[1];
var selected2 = vm.groups()[1].children()[0];
vm.selectedOptions.push(selected1);
vm.selectedOptions.push(selected2);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1453 次 |
最近记录: |