Knockoutjs - 表格行点击绑定,想要从点击事件中排除列
我正在尝试使用淘汰赛将点击绑定到表中的一行,如下所示:
<tr data-bind="click: $root.selectItem">
效果很好。问题是当我尝试排除某些列执行单击操作时。我的行中有编辑和删除按钮,我不希望它们触发 selectItem 单击事件。我是否只需将我想要以这种方式表现的所有 td 绑定到单击事件,还是有更简单的方法来做到这一点?
I am trying to use knockout to bind a click to a row in a table like this:
<tr data-bind="click: $root.selectItem">
It works great. The problem is when I try to exclude certain columns from taking the click action. I am have edit and delete buttons in my row and I don't want them firing the selectItem click event. Am I going to just have to bind all the td's I want to behave this way to the click event or is there an easier way to do it?
Fiddle here: http://jsfiddle.net/blankasaurus/WYKEM/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:您可以通过添加
clickBubble: false
作为与click
绑定的附加绑定来避免自定义绑定,如 Kevin Obee 建议并在本示例中演示:http://jsfiddle.net/kevinobee/Q25ja/2/原文:您可以使用自定义绑定来包装
click
绑定并防止发生其他事件。它可能看起来像:这是一个示例: http://jsfiddle.net/rniemeyer/xj7Hs/
Update: you avoid a custom binding by adding
clickBubble: false
as an additional binding with theclick
binding as suggested by Kevin Obee and demonstrated in this sample: http://jsfiddle.net/kevinobee/Q25ja/2/Original: You can use a custom binding that wraps the
click
binding and prevents additional events from happening. It might look like:Here is a sample: http://jsfiddle.net/rniemeyer/xj7Hs/