更改应用敲除绑定的顺序 [英] Changing order that Knockout bindings are applied

查看:53
本文介绍了更改应用敲除绑定的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Knockout绑定,它将用作jQuery小部件的包装.此小部件将事件处理程序应用于子元素.不幸的是,小部件的事件处理直接应用于子元素,而不是委派.问题是我在同一元素上具有foreach绑定,但是我需要在应用foreach绑定后 应用自定义绑定.

I'm creating a Knockout binding that will work as a wrapper around a jQuery widget. This widget applies event handlers to child elements. Unfortunately, the widget's event handling is applied directly to the child elements, not delegated. The issue is that I have a foreach binding on the same element, but I need the custom binding to be applied after the foreach binding is applied.

很显然,正确的方法是修复jQuery插件,但这不是当前的选择.我想知道是否有适合我的解决方法.例如,是否可以执行以下任一操作?

Obviously, the right thing is to fix the jQuery plugin, but this isn't an option at this time. I'm wondering if there are any good workaround options for me. Is there way, for example, to do any of the following?

  1. 检测是否已应用特定绑定
  2. 影响绑定应用程序的顺序
  3. 安全地强制进行另一次绑定

更新:

我应该提到的一个方面是此自定义和foreach绑定位于模板中.因此,直接修改DOM的解决方案对我不起作用,因为它实际上会修改模板.

One aspect I should mention is that this custom and foreach binding reside in a template. Therefore, solutions that directly modify the DOM won't work for me since it will actually modify the template.

推荐答案

如果您的绑定依赖于foreach绑定,为什么不从您的自定义绑定中调用它呢?然后,您甚至不需要在data-bind属性中提供它.前几天,我帮助了另一位SO用户,检查如何在自定义绑定中调用选项绑定

If your binding is dependant on foreach binding, why not call it from your custom binding? Then you don't even need to supply it in the data-bind attribute. I helped another SO user the other day, check how I call the options binding from within the custom binding

http://jsfiddle.net/w9bsc/42/

ko.applyBindingsToNode(element, { options: valueAccessor(), optionsCaption: caption, optionsText: optionsText  }, viewModel);

这篇关于更改应用敲除绑定的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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