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

查看:59
本文介绍了当我使用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天全站免登陆