为什么我的活动在foo
冒充bar
后才被解雇?
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");
答案 0 :(得分:2)
您必须从myEvent
发布foo
并将emitFacade
设置为true
。 http://yuilibrary.com/yui/docs/event-custom/#facade
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");
});
});