当我使用 jquery .val('xyz') 时,Knockout.js 绑定输入值未更新 [英] Knockout.js bound input value not updated when I use jquery .val('xyz')

查看:26
本文介绍了当我使用 jquery .val('xyz') 时,Knockout.js 绑定输入值未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入,该输入具有与该值的敲除绑定.

I have an input that has a knockout binding to the value.

当我使用 jquery 的 .val() 方法更新值时,更改后的值不会反映在 viewModel 中.

When I update the value using jquery's .val() method, the changed value is not reflected in the viewModel.

我需要使用 jQuery 来设置这个值.如何触发对 viewModel 的更新?

I need to use jQuery to set this value. How can I trigger the update to the viewModel?

推荐答案

.val() 不会触发更改事件.因此,您只需执行 .val("blah").change() 即可让 KO 获取更改.

.val() does not trigger the change event. So, you can just do .val("blah").change() for KO to pick up the changes.

这篇关于当我使用 jquery .val('xyz') 时,Knockout.js 绑定输入值未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆