English 中文(简体)
Emberjs 路由器: 当url hash 被更改时, 状态不会改变
原标题:Emberjs Router: state does not change when the url hash is changed

Emberjs core has a new router implementation which extends Ember.StateManager. This is the basic router I have currently implemented (using coffeescript):

Emee.set "stateManager", Ember.Router.create
    location: "hash"
    enableLogging: true

    start: Ember.State.extend
        index: Ember.State.extend
            route: "/"
            connectOutlets: (manager) ->
                console.log(manager)

        tasks: Ember.State.extend
            route: "/tasks"

            index: Ember.State.extend
                route: "/"

            show: Ember.State.extend
                route: "/show"

        users: Ember.State.extend
            route: "/users"

            index: Ember.State.extend
                route: "/"

Emee是我的Ember命名空间 我有几个问题要问:

1) When a page is loaded with a url with a hash http://localhost:3000/#tasks it moves to the correct start.tasks.index state, but on hashChange it just sends a message to the routePath of the current state. Emee.stateManager.route("/tasks") also does the same thing. It does not change the state and sends a message to routePath of the current state. Do we need to implement routePath ourselves? If not how do we change state by providing a route?

2( 2) 我可以看到许多改变, 哪个函数会被调用到进入状态。 从现在起, “ 连接输出” 似乎是调用进入状态的函数的名称 。 现在这个页面是否是设置控制器的正确页面?

UPDATE

更新了最新版本的混合代码。 我的路由器现在看起来像这个:

Emee.Router = Ember.Router.extend
    location: "hash"
    enableLogging: true

    root: Ember.State.extend
        index: Ember.State.extend
            route: "/"
            redirectsTo:  tasks.index 

        tasks: Ember.State.extend
            route: "/tasks"

            index: Ember.State.extend
                route: "/"
                connectOutlets: (manager) ->
                    console.log("in index");

            show: Ember.State.extend
                route: "/show"
                connectOutlets: (manager) ->
                    console.log("in show");

        users: Ember.State.extend
            route: "/users"

            index: Ember.State.extend
                route: "/"

Emee.initialize()

前向和后向浏览器按钮仍然不起作用。 它们称为 < code> routePath , 它们只是返回, 因为它们都是叶节点。 我认为我漏掉了一些小东西, 但无法将手指放在它上 。

最佳回答

This seems to be a bug in the current implementation of the router Check out the comment left by the developers at https://github.com/emberjs/ember.js/issues/887#issuecomment-5946213 for a workaround.

问题回答

最后钉钉钉如下:)至0.9.8.1时,我们需要调整https://github.com/emberjs/ember.js/issues/887#issuesimissuescomment-5946213 提供的工作。如下,在创建 Ember.Location 对象时,将“实施”改为“风格”。

Ember.Application.reopen({
  setupStateManager: function(stateManager) {
    var location = Ember.get(stateManager,  location );

    if (typeof location ===  string ) {
      location = Ember.Location.create({style: location});
      Ember.set(stateManager,  location , location);
    }

    stateManager.route(location.getURL());
    location.onUpdateURL(function(url) {
      stateManager.transitionTo( root );
      stateManager.route(url);
    });
  }

});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签