<上的applyBindings();选择>正在导致我的subscribe()起火,
applyBindings() on <select> is causing my subscribe() to fire,
我有一个选择:
<select class="form-control" data-bind="value: title.value, foreach: title.choices">
<option data-bind="text: name, value: code"></option>
</select>
带Js:
self.title.choices = [
{ "code": "", "name": "" },
{ "code": "MR", "name": "Mr" },
{ "code": "MRS", "name": "Mrs" }
]
self.title.value = ko.observable('').extend({
required: true
});
self.title.value.subscribe(function (newValue) {
self.gender.value('male');
});
然后,我调用applyBindings,选择列表在选项上迭代,并激发我的订阅函数3次(每个选项1次)。令人恼火的是,它会更新我的其他可观察到的内容,我该如何防止这种情况发生?
请改用options
绑定。
<select class="form-control" data-bind="value: title.value,
options: title.choices,
optionsText: 'code',
optionsValue: 'name',
optionsCaption: ''">
</select>
self.title.choices = [
{ "code": "MR", "name": "Mr" },
{ "code": "MRS", "name": "Mrs" }
];
self.title.value = ko.observable('').extend({
required: true
});
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 可以't让我的if语句处理js中的html表单输入
- 我的单元测试选项是什么
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 我的职位回报太快了,如何做出承诺
- 我的jQuery插件参数没有正确启动,遇到了问题
- 如何识别我的网站中的慢速设备
- 如何将JSON数据导入我的ejs模板
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 知道为什么我的旋转木马不会自动更改图片吗
- 我的模板未被解析
- 无法将数据从firebase获取到我的html页面
- 角度图表;t显示在我的页面中
- 我的AngularJS表达式没有'不起作用
- 将电视直播频道从网站嵌入我的网站
- /undefined在我的404错误日志中多次出现
- 为什么我的d3.jsselectAll+过滤器没有过滤
- 元素在我的代码中不会.fadeTo.Don'I don’我不知道;s错误的JavaScript、JQuery、H
- 我的javascript for循环不起作用
- <上的applyBindings();选择>正在导致我的subscribe()起火,