按钮单击以将选项标题值设置为挖空中的默认值



我目前正在研究淘汰赛中的选项绑定,绑定正在按照我的要求为我做所有事情。但目前我面临的问题是

如何设置选项标题值再次设置为按钮上的选择框 点击。

这是我的代码

 var clickMe = function(){
//Do Something 
    alert("I am working");
    //Want to enable optionsCaption Value again as current value in select box
};
var operator = ko.observable();
var vm = 
 {
     operators : [
{id: 0, name: 'addition'},
{id: 1, name: 'subtraction'},
{id: 2, name: 'division'},
{id: 3, name: 'multiplication'}
   ],
 operator:operator,
 clickMe: clickMe
}
 ko.applyBindings(vm);

目录

<select data-bind="options: $root.operators, optionsText: 'name', optionsValue: 'id', value: $root.operator, optionsCaption: 'Select Text'"></select>
<button data-bind="click: clickMe">Enable Caption</button>

请通过编辑我的小提琴手来回答。
提琴手链接

您需要

operator属性设置回nullundefined,以在选择中取回optionsCaption值:

var clickMe = function(){
//Do Something 
    alert("I am working");  
    vm.operator(undefined);
};

演示 JSFiddle。

最新更新