javascript 如何更改剑道绑定 html 输入的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15954977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the value of a kendo bound html input
提问by Flores
I have a kendoui grid with a custom popup for editing.
我有一个带有用于编辑的自定义弹出窗口的 kendoui 网格。
In this popup I have an input which is bound to a value of the grid:
在这个弹出窗口中,我有一个绑定到网格值的输入:
<input type="text" class="k-input k-textbox" id="test" data-bind="value:SearchFilter">
This works fine. Click edit in the grid, change the value in the textbox and the value propagates to the grid.
这工作正常。单击网格中的编辑,更改文本框中的值,该值将传播到网格。
But now I want to change the value of the textbox in javascript.. So I now have this:
但是现在我想更改 javascript 中文本框的值。所以我现在有这个:
$('#test').val("testvalue");
This indeed changes the value of the textbox, but upon save the new value isn't propagated to the grid. I guess because no change event occurs on the textbox.
这确实会更改文本框的值,但在保存时新值不会传播到网格。我猜是因为文本框上没有发生更改事件。
How do I make this work?
我如何使这项工作?
回答by Mihail
You need simulate change event. Try this code:
您需要模拟更改事件。试试这个代码:
$('#test').val("testvalue").change();
回答by user3833583
I tried the above answer but did not work for me. Although the value had indeed changed, the view did not reflect that fact. This worked for me:
我尝试了上述答案,但对我不起作用。尽管价值确实发生了变化,但该观点并未反映这一事实。这对我有用:
var myvar = $("#myid").data("kendoNumericTextBox");
myvar.value("newValue");
myvar.trigger("change", { value: myvar.value() });