我正在使用 ember.js 1.2,在对我的模型进行 CRUD 操作期间尝试显示加载微调器和通知消息时遇到问题。
代码如下:
var MyModelController = Ember.ObjectController.extend({
needs: ['application'],
application: Ember.computed.alias("controllers.application"),
actions: {
save: function() {
var _this = this;
// Display the spinner
this.get('application').get('loading').trigger(true);
this.get('model').save().then(function(response) {
// Hide the spinner
_this.get('application').get('loading').trigger(false);
// Display the success message
_this.get('application').get('flash').success('The model has been updated.');
}, function(response) {
// Hide the loading spinner
_this.get('application').get('loading').trigger(false);
// Display the error message
_this.get('application').get('flash').danger('Error updating the model.');
});
}
}
});
这里有两个主要问题:
首先:显示微调器需要 0.5 秒的翻译,但执行保存操作的持续时间更短,并且微调器显示并立即消失。在这里,我想在我的模型上调用保存操作之前设置一个 1s 计时器,以确保正确执行动画。怎么可能?
第二:我的 flash 对象上的成功方法绑定(bind)到模板上的特定 {{view.message}}。如果我在 promise 的“then”之外调用此方法,则消息会很好地显示,但在我的情况下,这不像绑定(bind)未完成。我是否错过了使用 promise 的方式?怎么可能显示这条消息?
最佳答案
关于javascript - 恩伯斯 : how to display loading spinner and notification messages on model operations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20687215/