2

我需要将 jquery 拨动开关与淘汰赛 observables 绑定,请帮助我正确的方法,因为我的不工作

我的 html 文件如下所示:

HTML:

<select name="toggleswitch1" id="toggleswitch1" data-theme="b" data-role="slider" data-bind="option:activateNotification">
    <option value="false">No</option>
    <option value="true">Yes</option>

和视图模型是:

Javascript:

function selectVM(){
    self = this;
    self.activateNotification = ko.observable(true);
}
4

2 回答 2

1

Not 100% sure what you're trying to do but if you are trying to bind the selected option you have to use value: activateNotification

于 2013-07-17T13:11:11.847 回答
1

这是一个可行的小小提琴:http: //jsfiddle.net/9X5j8/

网页:

<select name="toggleswitch1" id="toggleswitch1" 
data-theme="b" data-role="slider" 
data-bind="value:activateNotification">
<option value="false">
     No
</option>
<option value="true">
  Yes
</option>
</select>

    <span data-bind="text :activateNotification"></span>

JS:

function selectVM(){
   self = this;
   self.activateNotification = ko.observable(true);
}

var vm = new selectVM();
ko.applyBindings(vm);

您可能希望为您的 observable 提供与 select 的第一个选项相同的默认值。

于 2013-07-17T13:15:44.380 回答