更改应用敲除绑定的顺序 [英] Changing order that Knockout bindings are applied
问题描述
我正在创建一个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?
- 检测是否已应用特定绑定
- 影响绑定应用程序的顺序
- 安全地强制进行另一次绑定
更新:
我应该提到的一个方面是此自定义和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
ko.applyBindingsToNode(element, { options: valueAccessor(), optionsCaption: caption, optionsText: optionsText }, viewModel);
这篇关于更改应用敲除绑定的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!