2017-04-22 2 views
1

일부 프로젝트의 경우 녹아웃ASP.NET MVC을 사용하고 있습니다.
나는 녹아웃녹아웃 맞춤 바인딩 "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를 사용하고 난 this question에서이 코드를 있고 난 그것을 조금 수정했습니다.
기본적으로 Select2 plugin의 경우 custom binding handler입니다.

난 그냥 after: ["options", "value", "selectedOptions"], 여기에 무엇을 의미하는지 알고 싶어
질문
. init 또는 update 함수에는이 변수에 대한 참조가 없습니다.
이 컨텍스트에서이 변수가 의미가 있습니까? 또는이 실행을 마친 후 사용자 정의 바인딩을 실행하게하는 녹아웃 명령입니다 [options, value, selectedOptions] 바인딩?

참고 custom binding의 설명서에는이 변수에 대한 언급이 없습니다.

답변

1

당신은 그것이 문서화되지 않은 것으로 보입니다.

// 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 source code에 파고이 우리에게 보여줍니다. KO는 현재 바인딩이 실행되기 전에 실행해야하는 종속 바인딩 목록을 작성 중입니다. 내장 된 valueselectedOptions 바인딩은이 키워드를 이용합니다. 여기

여기에 관련 StackOverflow answer

이 예제 코드에 대한 그 대답에 JSFiddle를 참조입니다 discussion on implementation from the Knockout Github

입니다.