tho*_*ens 5 coffeescript ember.js
假设我有一个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)
Run Code Online (Sandbox Code Playgroud)
如何从其他路线触发此操作?请注意,因为我需要调用@transitionTo,所以这段代码必须在路由中.
默认情况下,操作会冒泡到应用程序路径!只需{{action 'goBack'}}在您的模板中使用,或从代码(减去组件)调用this.send('goBack').从组件中您需要连接事件调用稍微不同并使用this.sendAction('internalActionName').
http://emberjs.jsbin.com/ulIhUze/1/edit
| 归档时间: |
|
| 查看次数: |
2930 次 |
| 最近记录: |