2
在某些情況下,我遇到了路由URL的問題。這裏是我的路由器:在某些情況下,帶有參數的Emberjs路由失敗
contacts: Em.Route.extend({
route: '/contacts',
index: Em.Route.extend({
route: '/',
connectOutlets: function(router, context) {
App.contactsController.populate()
var appController = router.get('applicationController');
appController.connectOutlet('contactsList');
}
}),
show: Em.Route.extend({
route: '/:contactid',
connectOutlets: function(router, context) {
alert('show contact');
}
}),
doShowContact: function(router, event){
router.transitionTo('show', {contactid: event.context.id});
}
}),
當我裏面doShowContact進入,如果我指定「的ContactID」爲背景和「/:使用ContactID」作爲內「秀」路線,我會爲例如「/contacts/3'在瀏覽器網址中,一切正常。
然而,在doShowContact,如果我指定'CONTACT_ID'而不是'的ContactID'爲背景和'/:CONTACT_ID'而不是'/:使用ContactID'的路線。我會在瀏覽器網址中獲得'/ contacts/undefined'。
有沒有辦法解釋它?謝謝!
非常感謝邁克。它現在效果更好。在路線中指定一個modelClass是否很重要? – ThomasDurin 2012-07-27 12:22:09
該類將用於模型實例查找(ember-data模型的查找) – 2012-07-27 15:46:57
@Thomas將從參數名稱中提取模型類:'user_id'將假定模型爲'YourNamespace.User',而'repository_id'將會asume'YourNamespace.Repository'。如果使用這個約定,則不需要明確指定'modelClass'。 – pangratz 2012-07-27 15:51:02