本文介绍了输入值更改时的Knockout值绑定除了'afterkeydown'之外不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有敲除装订的文本框如下。

I have a text box with knockout binding as follows.

<input style="width: 385px; float: right" type="text" id="SymptomBox" placeholder="Symptoms" data-bind ="value : acceptedSymptom,valueUpdate:['afterkeydown'],event:{keypress:AddSymptoms}"/>





我的视图模型如下



My view model is as follows

var ViewModel = function (data) {
var self=this;
self.acceptedSymptom=ko.observable();
}
ko.applyBindings(ViewModel);



每次按下键盘键,我都可以更新可观察数组acceptedSymptom。显然,这是由于valueUpdate:['afterkeydown']属性绑定到我的输入文本框。这很好,但我也希望可观察数组更新值,而我更改输入文本框除了keydown之外的值。例如,我有一个JQuery自动完成插件集成到上面提到的文本框。虽然我通过鼠标点击下拉选择任何菜单项,observablearray应该改变值与输入文本框的值的变化。请注意,如果我选择下拉值,使用键盘它工作正常。只有问题是用鼠标指针选择不更新可观察数组。除了'afterkeydown',我还尝试了valueUpdate:['input','afterkeydown','change','blur','负载']。这些都没有任何意义。请帮助我....


I can update the observable array "acceptedSymptom" each time i press a key with key board.Clearly it is due to valueUpdate:['afterkeydown'] attribute binding to my input text box.This works fine,but i also want observable array to update value while i change value of input text box other than keydown.For example,i have a JQuery autocomplete plugin integrated to above mentioned text box.While i select any menu item from drop down by mouse click,observablearray should have changed value with change in value of input text box.It is noted that if i am selecting drop down values,using keyboard it works fine.Only issue is with selection with mouse pointer do not update observable array.Other than 'afterkeydown', i have also tried valueUpdate:['input','afterkeydown','change','blur','onLoad']. None of these make any sense.Please help me....

推荐答案

document.getElementById("changeit").addEventListener("click", function(){
    document.getElementById("SymptomBox").value = "new value";






简单示例:





[]


这篇关于输入值更改时的Knockout值绑定除了'afterkeydown'之外不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 10:40