Ember.js获得当前路线

She*_* Yu 6 ember.js ember-router

我正在切换到新的ember路由器,但有一个非常简单的问题 - 我如何找出我目前的路线?在您做某事之前App.router.get('currentState'),这似乎不再起作用,因为路由器不再继承StateManager

mav*_*ein 8

看看这个问题.

简介:currentState现在存储在currentPathApplicationController 的属性中.接受的解决方案是观察此属性以将其写入全局属性:

App = Em.Application.create({
    currentPath: ''
});
ApplicationController : Ember.Controller.extend({
    updateCurrentPath: function() {
        App.set('currentPath', this.get('currentPath'));
    }.observes('currentPath')
});
Run Code Online (Sandbox Code Playgroud)


and*_*pop 6

我可能会对此感到沮丧,但在对此感到沮丧之后,我决定实施一个非常难看的解决方法.

我的用例是试图获取当前帖子的ID,因为我发布了回复.对我们当前的路线考虑这样的事情:

" ...#/后/ 12345"

我的解决方法(最丑陋的代码):

var currentId = window.location.hash.split('/')[2];
 App.Message.createRecord({
      content: message,
      inReplyTo: currentId
    }).get('transaction').commit();
Run Code Online (Sandbox Code Playgroud)

  • +1没有人可以责怪你实际完成你想要的东西,即使它沿着"丑陋"的方式. (2认同)