2012-06-07 89 views
0

我无法理解Ember.js路由如何工作,特别是如何使用路由中的动态段。通过Ember.js路由使用动态段

例如,如果您想从重置密码页抓取标记并在表单提交中使用该标记,那么您将如何获取标记?下面的代码尝试在页面上打印标记作为中间步骤,但它不会呈现TokenView。什么做错了?谢谢。

window.App = Em.Application.create({}); 

App.IndexView = Em.View.extend({ 
    template: Em.Handlebars.compile(
     '<h1>Index</h1>' 
    ) 
}); 

App.ResetView = Em.View.extend({ 
    template: Em.Handlebars.compile(
     '<h1>reset view </h1>' 
    ) 
}); 

App.TokenView = Em.View.extend({ 
    template: Em.Handlebars.compile(
     '<h1>token view {{token_id}}</h1>' 
    ) 
}); 

App.Router = Ember.Router.extend({ 

    rootElement:'#content', 
    location: 'hash', 
    enableLogging: true, 

    root: Ember.State.extend({ 

     index: Ember.ViewState.extend({ 
      route: '/', 
      view: App.IndexView 
     }), 

     passwordReset: Ember.ViewState.extend({ 
      route: '/reset', 
      view: App.ResetView, 

      token: Ember.ViewState.extend({ 
       route: '/:token_id', 
       view: App.TokenView 
      }) 
     }) 
    }) 
}); 

App.router = App.Router.create(); 
App.initialize(App.router); 

回答

1

你应该看看艺术文档的状态大约Router这是正在进行的,但可用@https://emberjs-staging-new.herokuapp.com/guides/outlets#toc_the-router

+0

感谢麦克。这个文档看起来好多了,我以前没有找到。 – Brian

+1

我读了那页,上面提到的控制器,对象和模板的细节都丢失了,我一直在试图为这些东西存根。你有一个完整的例子吗? – Brian

+0

这里是一个完整的示例礼貌https://github.com/jbrown http://jsfiddle.net/justinbrown/C7LrM/10/ – Brian