ember-data:如何进行保存/保存的Flash消息 [英] ember-data: How to make a Saving/Saved flash message

查看:74
本文介绍了ember-data:如何进行保存/保存的Flash消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了使我的应用程序顶部有一个黄色的保存/保存指示符消息,我想要一个布尔属性,指示是否有任何ember数据记录正在运行。

In order to make a little yellow "Saving"/"Saved" indicator message at the top of my app, I'd like to have a boolean property indicating if any ember-data records are currently in flight.

我尝试过:

App.store = DS.Store.create
  isSaving: (->
    for record in this.get('recordCache')
      if record?.getPath('stateManager.currentState.name') == 'inFlight'
        return true
    return false
  ).property('recordCache.@each.stateManager.currentState.name')

但是我发现 recordCache 是不可观察的。

but then I discovered that recordCache is not observable.

t使用交易,只有 App.store.commit(),所以我看了 App.store.get('defaultTransaction'),但它没有任何有用的东西。

I don't use transactions, only App.store.commit(), so I looked at App.store.get('defaultTransaction'), but it didn't yield anything useful.

我正在使用RESTAdapter,所以如果我可以将其扩展到给我这个信息,那么也会工作。

I'm using the RESTAdapter, so if I can extend it into giving me this piece of information, that would work too.

推荐答案

嗯,你可以用一个doUpdate属性创建一个基本模型,它处理显示你的通知消息,然后让你的每一个模型都扩展。这实际上是一个暂时的解决方案,但它暂时适用:

Well, you could simply create a base model with a didUpdate property that handles showing your notification message, then have each of your models extend it. It's really a stop-gap solution, but it works for the time being:

App.Model = DS.Model.extend
    didUpdate: ->
        # invoke your notification
        alert("All changes saved!")

App.User = App.Model.extend()

但是....这将触发已更新的每个记录。因此,您可能希望创建通知类,使其不会立即打开多于一个保存的通知,但这取决于您。

However....this will fire for EVERY record that is updated. So you'd probably want create your notification class in such a way that it will not open more then one saved notification at once...but that's up to you.

我目前正在从这个拉动请求中 https://实现一些基本的服务器验证方法。 github.com/emberjs/data/pull/376 ,我希望我能提出一个更好的方式来观察提交的状态(如果我这样做,当然会发布到这里)。

I'm currently working on implementing some of the basic server-validation methods from this pull request https://github.com/emberjs/data/pull/376, and I'm hoping that I'll come up with a better way to observe the status of commits (and will of course post back here if I do).

这篇关于ember-data:如何进行保存/保存的Flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆