我正在尝试在optgroups
中呈现我的类别,并在品牌中动态更改itemsCount
。
当我动态地将itemsCount
0更改为正值时,所选选项也会更改(仅更改UI,而不是可观察到的更改)。
<select class="form-control brand-selector pull-left"
data-bind="value: $data.selectedBrand">
<!-- ko if:$data.popularBrands().length -->
<optgroup label="popular brands" data-bind="foreach:$data.brands">
<!-- ko if: $data.itemsCount -->
<option data-bind="text: $data.Caption, option: $data"></option>
<!-- /ko -->
</optgroup>
<!-- /ko -->
<!-- ko if:$data.possibleBrands().length-->
<optgroup label="All possible families" data-bind="foreach:$data.brands">
<!-- ko ifnot:$data.itemssCount -->
<option data-bind="text: $data.Caption, option: $data"></option>
<!-- /ko -->
</optgroup>
<!-- /ko -->
</select>
如何阻止所选的选项更改?