【问题标题】:Ember.js: Call actions of ApplicationRoute from nested routeEmber.js:从嵌套路由调用 ApplicationRoute 的操作
【发布时间】:2013-11-12 12:27:36
【问题描述】:

假设我有一个ApplicationRoute 和一个动作goBack(正如您在评论中看到的,由于不同移动浏览器中的错误,我需要自己处理 goBack):

Mobile.ApplicationRoute = Em.Route.extend
    actions:
        goBack: ->
            # TODO: Remove when iOS 7 fixed their history
            # If there's no route to go back, go to front
            # TODO: Remove when Microsoft fixed their
            # back button in offline mode
            if not (Nn.MobileHelper.isiPhone() or Nn.MobileHelper.isIeMobile()) and @get("router.recentRoute")?
                return window.history.back()

            @get("controller").set("isHitBackButton", true)

            @transitionTo("front").then => @get("controller").set("isHitBackButton", false)

如何从另一条路线触发此操作?请注意,由于我需要调用@transitionTo,因此这段代码必须在路由内。

【问题讨论】:

    标签: ember.js coffeescript


    【解决方案1】:

    默认情况下,动作冒泡到应用程序路由!只需在模板中使用{{action 'goBack'}},或从代码(减去组件)调用this.send('goBack')。从组件中,您需要连接事件调用有点不同并使用this.sendAction('internalActionName')

    http://emberjs.jsbin.com/ulIhUze/1/edit

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 1970-01-01
      • 2013-07-20
      • 2012-11-18
      • 1970-01-01
      • 2014-05-25
      • 2013-09-26
      • 2015-03-18
      • 1970-01-01
      相关资源
      最近更新 更多