2016-07-15 85 views
0

我想通过淘汰赛js将选定的下拉列表中的值传递给我的视图模型。如何使用淘汰赛将选定选项传递给可观察阵列

<select class="form-control" style="width:auto" data-bind="options: clients, optionsCaption: 'Choose...', optionsText: 'name', optionsValue: 'value', value: 'selectedCustomer'"></select>

在我的视图模型,我宣布一个KO观察到的存储选择的值:

self.selectedCustomer = ko.observableArray([]);

变量,当我选择一个值是没有得到填充。有小费吗?谢谢!

回答

1

我可以看到两个问题的代码:

你的价值结合到observableArray,但所选择的选项将是一个单一的客户,以便observable应改为使用。

值(value: 'selectedCustomer')也不应该用单引号包装,因为那样你就有效地试图绑定到一个字符串而不是可见的。

尝试以下:

<select class="form-control" style="width:auto" data-bind="options: clients, optionsCaption: 'Choose...', optionsText: 'name', optionsValue: 'value', value: selectedCustomer"></select> 

然后在视图模型:

self.selectedCustomer = ko.observable(); 
+1

这一工程!谢谢!两个愚蠢的引号...... – manufan22122