knockout.js并在复选框上侦听检查事件 [英] knockout.js and listen to check event on checkbox

查看:658
本文介绍了knockout.js并在复选框上侦听检查事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取一个函数来执行时复选框被选中或取消选中,以验证所有复选框未选中,但它从来没有被执行。

  @ Html.CheckBox(Subscription,new {data_bind =disable:已禁用,已检查:已检查,请点击:$ parent.allSubscriptionsUnchecked})


解决方案>

您可以添加已选中单击绑定到输入。但是,您需要从点击处理程序 return true; 。这将允许默认操作继续(复选框将被选中/取消选中)。



这里是一个示例:http://jsfiddle.net/rniemeyer/cnkVA/



另一种方法是将此逻辑推送到视图模型中并订阅对布尔观察值的更改并执行您的操作,如: http://jsfiddle.net/rniemeyer/cnkVA/2/


I'm trying to get a function to execute when a checkbox is checked or unchecked to verify all checkboxes are unchecked but it never gets executed. I assume I'm not doing it correctly.

@Html.CheckBox("Subscription", new{ data_bind="disable: Disabled, checked: Checked, click: $parent.allSubscriptionsUnchecked"} ) 

解决方案

You can add both a checked and click binding to an input. However, you would want to return true; from the click handler. This will allow the default action to proceed (the checkbox will be checked/unchecked).

Here is a sample: http://jsfiddle.net/rniemeyer/cnkVA/

An alternative technique is to push this logic into your view model and subscribe to changes to a boolean observable and execute your action like: http://jsfiddle.net/rniemeyer/cnkVA/2/

这篇关于knockout.js并在复选框上侦听检查事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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