2013-08-08 2 views
0

내 이벤트가 foo에 발사되지 않는 이유는 무엇입니까? bar?Y.Node addTarget 이벤트가 버블 링하지 않습니다.

var foo = Y.one(".foo"), 
    bar = Y.one(".bar"); 

foo.addTarget(bar); 

foo.on("myEvent", function() { 
    //this log statement executes 
    Y.log("In foo listener"); 
}); 

bar.on("myEvent", function() { 
    //this log statement doesn't execute. 
    //I don't understand why. I think it 
    //should because I expect myEvent to 
    //bubble from foo to bar since I used 
    //addTarget 
    Y.log("In bar listener"); 
}); 

foo.fire("myEvent"); 

JS 바이올린 : http://jsfiddle.net/steaks/tJnLf/

답변

2

당신은 foo에서 myEvent를 게시해야하고 trueemitFacade을 설정합니다. http://yuilibrary.com/yui/docs/event-custom/#facade

http://jsfiddle.net/tJnLf/27/

YUI().use('event-custom', 'node', function(Y) { 
    Y.on('domready',function(e) { 
     var foo = Y.one(".foo"), 
      bar = Y.one(".bar"); 

     foo.publish("myEvent", { 
      emitFacade: true 
     }); 

     foo.addTarget(bar); 

     foo.on("myEvent", function() { 
      Y.log("In foo listener"); 
     }); 

     bar.on("myEvent", function() { 
      Y.log("In bar listener"); 
     }); 

     foo.fire("myEvent"); 
    }); 
}); 
+0

감사합니다! 나는이 대답을 막 쓰려고했다. –

관련 문제