我正在使用knockoutjs
我有一个下拉列表。我的下拉列表对应于一个名为 (booleanValue) 的布尔可观察变量,具体取决于用户选择 (true, false)。该功能正常工作,但我想更改下拉列表文本。例如,我希望它是 All,而不是 true,而对于 false,我希望是 none。到目前为止,这是我的代码:
html 选择标签:
<select data-bind="options: availableOptioons, selectedOptions: booleanValue, value :booleanValue"></select>
我的视图模型
function ViewModel(model) {
this.booleanValue= ko.observable(model.BooleanValueComingFromServer);
this.availableOptioons = ko.observableArray([true,false]);
};
我还根据 booleanValue 隐藏和显示一些 html:
<table class="form" style="width: 100%">
<tbody>
<tr data-bind="visible: booleanValue">
<td>Team</td>
<td>Score</td>
</tr>
<tr data-bind="visible: !$root.booleanValue()">
<td>Student</td>
<td>Grade</td>
</tr>
</tbody>
</table>
正如我之前提到的,更改下拉列表选择的值将UI
正确更改。我只是想改变 true --> all,false --> none。
任何想法我怎么能做到这一点?
谢谢。