0

我目前有一个具有以下应用程序和视图的应用程序。我希望能够在我的应用程序的各个时间点闪烁这些通知。我当前的 emberscripts 文件包括

class Candidate.ApplicationController extends Ember.ArrayController
    alerts: Ember.Object.create
        success: [
            'TaDa!'
            'Here we go!'
        ]
        error: [
            'What did you do now!?'
        ]

Candidate.AlertsView = Ember.View.extend
    templateName: 'views/alerts'

Candidate.AlertView = Ember.View.extend
    templateName: 'views/alert'

    class: (->
        return 'alert alert-' + @type
    ).property()

    close: ->
        @$().slideUp 'normal', =>
            @destroy()

我的车把view/alerts看起来像这样:

{{#each alerts.success}}
    {{view Candidate.AlertView messageBinding=this type="success"}}
{{/each}}

views/alert

<div {{bindAttr class="view.class" }}>
    <i class="icon-remove-sign"></i>
    <button type="button" class="close" {{action 'close' target='view'}}>×</button>
    {{view.message}}
</div>

现在这对于初始化值很好,但有一些问题。

  1. 它不允许我添加新警报
  2. 关闭函数不会从应用程序控制器上的警报对象中删除警报

我将如何使它更接近会话闪存警报消息包,例如服务器上可用的消息包?

这是当前代码的 JSBin:http: //jsbin.com/ejAS/1/

4

4 回答 4

1

您可以使用 ember 组件查看此示例http://jsbin.com/AQuQILI/8/edit?html,js,output 我希望这可以帮助您

于 2013-08-26T21:03:38.123 回答
1

查看Ember 的 Bootstrap 以获得更完整的通知组件。

它支持自动淡入/淡出消息,将鼠标悬停在通知上使其不会淡出,因此用户可以有更多时间阅读它,可以配置显示时间/淡入/淡出时间等...

演示:

http://ember-addons.github.io/bootstrap-for-ember/dist/#/show_components/notifications

于 2013-08-30T19:45:56.010 回答
0

After doing some more research on passing around data and understanding controllers more, I think I've actually gone with this approach.

http://jsbin.com/uhel/6/edit?html,js

While I'd really like to do the fade in and out, this seems to get the job done quite well.

于 2013-08-28T18:51:19.267 回答
0

我同意@Fab。警报应该由组件而不是视图或控制器构建,当然也不应该由 Bootstrap.js。这意味着我们将对小部件拥有更大的“Ember 世界控制”。

这里回答了另一个组件示例:如何使用 Ember.js 制作警报通知组件?

于 2014-11-21T21:07:20.437 回答