Javascript 淘汰:如何从自定义父绑定调用子绑定?

Javascript 淘汰:如何从自定义父绑定调用子绑定?,javascript,knockout.js,Javascript,Knockout.js,我对DOM中的元素进行了自定义绑定: <div data-bind="customBinding"> <div class="for-view" data-bind="text: Property"></div> <div class="for-edit" data-bind="childBinding"></div> </div> 在customBinding调用childBinding期间有没有

我对DOM中的元素进行了自定义绑定:

<div data-bind="customBinding">
     <div class="for-view" data-bind="text: Property"></div>
     <div class="for-edit" data-bind="childBinding"></div>
</div>

在customBinding调用childBinding期间有没有方法?看起来是这样的:

 if <$('.for-edit') element has binding of type childBinding>
     <process childBinding first>       //this part is a problem
 <continue customBinding>
if
//这部分是个问题
我的场景与内联编辑相关。customBinding负责设置内联编辑,根据子元素类和其他元素添加显示/隐藏绑定。
我遇到的问题是,现在我有一个自定义的childBinding来创建包装器。如果在customBinding之后发生了childBinding,那么我就有问题了。我需要在customBinding期间调用childBinding,然后停止dedent子绑定。

我想这是可能的,在任何情况下,对于敲除自定义绑定,您可以完全控制何时调用子绑定。我会让
customBinding
始终首先调用它的子绑定,类似于:

ko.bindingHandlers['customBinding'] = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        // apply bindings to child first
        ko.applyBindingsToDescendants(bindingContext, element);

        // ... Process Custom binding

        return { 'controlsDescendantBindings': true };
    }
};
然而,为什么对同一件事情有两个不同的绑定,这只会使事情变得更困难。为什么不将所有逻辑放在
自定义绑定中

ko.bindingHandlers['customBinding'] = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        $(element).find('.for-edit').each(function (i, x) {
            // apply child binding logic
        });

        // ... Process Custom binding
    }
};

希望这能有所帮助。

这里对customBinding和childBinding交互的情况描述得非常模糊,我们无法猜测实际情况。请提供每个自定义绑定、视图模型的代码,然后准确解释问题所在。此处提供的代码太复杂。我只需要知道是否有一个选项可以调用子绑定。换句话说,如果我有#elementid,我能以某种方式强制绑定它吗?