javascript - 恩伯斯 : how to display loading spinner and notification messages on model operations

标签 javascript binding ember.js ember-data promise

我正在使用 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/

相关文章:

c++ - 在 Node.js 和 v8 中调用使用包装对象作为参数的函数

wpf - 获取 ItemsControl 中的选定项目

ember.js - Ember中异步的一些问题

javascript - 客户端框架还是服务器端框架?

javascript - 如何将 iframe 视频播放器锚定到底部、左侧和右侧位置? HTML5 和 JavaScript

如果我改变某个地方,Javascript对象到处都会改变

javascript - 我正在尝试用一个对象填充 div

javascript - 如何在 php 代码中的 javascript 代码中使用 php 变量?

silverlight - MVVM 列表框更新内容维护所选项目 Silverlight

jquery - 将 RSVP.js 中的一系列 Promise 与 jQuery 的 $.ajax 集成