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