[英]How to invoke a method upon transition to another route in Ember?
可以说我有一个像这样的IndexController,
App.IndexController = Ember.ArrayController.extend({
sortProperties: ['PicId'],
PicCreated: function () {
alert('Pic created');
}
});
现在我有另一个名为NewPic的控制器
App.NewPic = Ember.Controller.extend({
// the initial value of the `search` property
model: this.get('model'),
needs: ["Index"], //says we need the Index controller for this
actions: {
var Pic= this.store.createRecord("PicList", obj);
PicList.save().then(function () {
this.transitionToRoute('Index');
});
}
});
我的问题是过渡时如何调用PicCreated。 我有图片列表,上传后,我将返回索引页面并显示消息“图片已创建”。
有人能帮助我吗?
transitionToRoute
返回一个promise,因此您可以使用then
来知道转换何时完成,并调用PicCreated
方法:
App.NewPic = Ember.Controller.extend({
needs: ["index"],
actions: {
createPic: function() {
var newPicController = this;
var indexController = this.get('controllers.index');
// more code here ...
PicList.save().then(function () {
newPicController.transitionToRoute('index').then(function() {
// show th message
indexController.PicCreated();
});
});
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.