2016-11-02 4 views

답변

0

사용자 지정 바인딩 동작 클래스 내에서 updateTarget()updateSource() 메서드를 재정 의하여 속성 값을 가로 챌 수 있습니다. 예 :

const interceptMethods = ['updateTarget', 'updateSource', 'callSource']; 

export class InterceptBindingBehavior { 
    bind(binding, scope, interceptor) { 
    let i = interceptMethods.length; 
    while (i--) { 
     let method = interceptMethods[i]; 
     if (!binding[method]) { 
     continue; 
     } 
     binding[`intercepted-${method}`] = binding[method]; 
     let update = binding[method].bind(binding); 
     binding[method] = interceptor.bind(binding, method, update); 
    } 

    binding.updateTarget = value => { 
     //do something with value; 
    } 

    binding.updateSource = value => { 
     //do something with value; 
    } 
    } 

    unbind(binding, scope) { 
    let i = interceptMethods.length; 
    while (i--) { 
     let method = interceptMethods[i]; 
     if (!binding[method]) { 
     continue; 
     } 
     binding[method] = binding[`intercepted-${method}`]; 
     binding[`intercepted-${method}`] = null; 
    } 
    } 
} 
+0

Fabio, 귀하의 제안에 감사드립니다. 그러나 bind()가 호출 될 때'updateTarget'은 소스의 _initial_ 값을 얻기 위해 작동하지 않습니다. _changes_ 값일 때만 호출됩니다. –