我正在为我的一个项目使用Ember app kit,我对RESTAdapter如何工作以及为什么在使用嵌套路由器时仅使用1个url有疑问。
我有“客户”模型并使用这样的路由器:
this.resource('customers', function(){
this.resource('customer', {path: '/:customer_id'});
});
//using these urls
http://myapp/index.html#/customers
http://myapp/index.html#/customers/1
在这种情况下,只有“/ customers”url被调用才能获取JSON数据,因为我猜它在从“/ customers”获得整个客户JSON数组后,按id = 1过滤整个JSON。
在另一种情况下,如果我使用像这样的非嵌套路由器“
this.resource('customers');
this.resource('customer', {path: '/customers/:customer_id'});
“/ customers”为第一个路由器检索JSON资源,为第二个路由器检索“/ customers / 1”。
所以我的问题是为什么会这样发生?有没有办法使用嵌套路由器,同时在需要时通过id分别保存和检索资源?
感谢。