2017-04-22 10 views
1

私はノックアウトASP.NET MVCのプロジェクトを使用しています。
私はthis questionからこのコードを持って、私は少しそれを修正ノックアウトノックアウトカスタムバインディング "after"変数とは何ですか?

ko.bindingHandlers.select2 = { 
    after: ["options", "value", "selectedOptions"], 
    init: function (el, valueAccessor, allBindingsAccessor, viewModel) { 
     // no explicit reference to the 'after' variable 
    }, 
    update: function (el, valueAccessor, allBindingsAccessor, viewModel) { 
     // no explicit reference to the 'after' variable 
    } 
} 

の次bindingHandlerを使用しています。
Select2 pluginの場合、基本的にはcustom binding handlerです。私はちょうどafter: ["options", "value", "selectedOptions"],がここで何を意味するのかを知りたい

質問
initまたはupdate関数のどこにでもこの変数への参照はありません。
このコンテキストではこの変数は意味を持ちますか?またはこれを完了した後にこのカスタムバインディングを実行させるためにノックアウトする指示ですか[optionsvalueselectedOptions]バインディング?

custom bindingのドキュメントには、この変数については何も記載されていません。

答えて

1

あなたは文書化されていないようです。 KO source codeを調べると、次のようになります。

// First add dependencies (if any) of the current binding 
if (binding['after']) { 
    cyclicDependencyStack.push(bindingKey); 
    ko.utils.arrayForEach(binding['after'], function(bindingDependencyKey) { 
     if (bindings[bindingDependencyKey]) { 
      if (ko.utils.arrayIndexOf(cyclicDependencyStack, bindingDependencyKey) !== -1) { 
       throw Error("Cannot combine the following bindings, because they have a cyclic dependency: " + cyclicDependencyStack.join(", ")); 
      } else { 
       pushBinding(bindingDependencyKey); 
      } 
     } 
    }); 
    cyclicDependencyStack.length--; 
} 

あなたの前提は正しいと思われます。 KOでは、現在のバインディングを実行する前に実行する必要がある依存バインディングのリストを作成しています。組み込みのvalueselectedOptionsバインディングはこのキーワードを利用します。ここで

はここdiscussion on implementation from the Knockout Github

ある関連StackOverflow answer

は、サンプルコードのためのその答えにJSFiddleを参照してくださいです。

関連する問題