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);
感謝麥克。這個文檔看起來好多了,我以前沒有找到。 – Brian
我讀了那頁,上面提到的控制器,對象和模板的細節都丟失了,我一直在試圖爲這些東西存根。你有一個完整的例子嗎? – Brian
這裏是一個完整的示例禮貌https://github.com/jbrown http://jsfiddle.net/justinbrown/C7LrM/10/ – Brian