我有以下代码,并希望设置一个选项为“选定”。我通常使用"optionsValue“来做这件事,但它在这里似乎不起作用。
<select data-live-search="true" data-bind="foreach: $parent.customers, event: {change: $parent.changeWorkCustomer($data, $element.value)}">
<option data-bind="text: customer_display_name, value: customer_id, attr: {'data-tokens': [customer_first_name(), customer_last_name(), css: { customer_fav: fav() > 0 }"></option>
</select>
你知道如何将一个选项设置为选中状态吗?
发布于 2018-08-30 05:06:51
通过将一个可观测对象绑定到select
来保存所选的选项值。
<select data-live-search="true" data-bind="foreach: $parent.customers,
event: {change: $parent.changeWorkCustomer($data, $element.value)},
value: selectedCustomer">
<option data-bind="text: customer_display_name, value: customer_id, attr: {'data-tokens': [customer_first_name(), customer_last_name(), css: { customer_fav: fav() > 0 }"></option>
</select>
// selects the option whose value is customerId1
this.selectedCustomer = ko.observable('customerId1');
https://stackoverflow.com/questions/52085666
复制相似问题