[英]How can I bubble up an Ember action inside a callback function?
I have an Ember application and I am using an action to apply a CSS animation. 我有一个Ember应用程序,我正在使用一个动作来应用CSS动画。 Once the animation is complete I want to bubble up the action from the controller to my route to handle further functionality. 一旦动画完成,我想将操作从控制器冒泡到我的路线以处理更多功能。
I know that if I return: true;
我知道如果我return: true;
the action will bubble up, as explained here . 该行动将泡涨,如解释在这里 。
This is what my controller looks like: 这就是我的控制器的样子:
App.MyController = Ember.ObjectController.extend({
actions: {
myAction: function() {
$('.my-element').addClass('my-animation-class').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
console.log('working');
return true;
}
}
}
});
If I log something to my console in my animationend
callback I can see it working and if I move return: true;
如果我在我的animationend
回调中将某些内容记录到我的控制台,我可以看到它正常工作,如果我移动return: true;
outside of the callback, the action bubbles up successfully. 在回调之外,该行动成功起泡。 However, returning true inside of the callback does not work. 但是,在回调内部返回true是行不通的。
What am I missing? 我错过了什么?
you can manually trigger the bubble by calling self.target.send('myAction');
您可以通过调用self.target.send('myAction');
手动触发气泡self.target.send('myAction');
an IndexController
defined like this 一个像这样定义的IndexController
App.IndexController = Ember.Controller.extend({
actions: {
bubbleMe: function(item){
var self = this;
alert('IndexController says you clicked on: ' + item);
setTimeout(function(){
self.target.send('bubbleMe',[item]);
}, 1000);
}
}
});
would bubble to an ApplicationRoute
defined like this 会冒泡到像这样定义的ApplicationRoute
App.ApplicationRoute = Ember.Route.extend({
actions: {
bubbleMe: function(item){
alert('ApplicationRoute says you clicked on: ' + item);
}
}
});
You can see a working fiddle here: http://jsfiddle.net/tikotzky/2ce9s32f/ 你可以在这里看到一个工作小提琴: http : //jsfiddle.net/tikotzky/2ce9s32f/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.