Javascript 什么';这个.route()和这个.resource()之间的区别是什么?
我知道路由用于将URL映射到模板,但显然您可以使用this.route或this.resource定义路由Javascript 什么';这个.route()和这个.resource()之间的区别是什么?,javascript,ember.js,Javascript,Ember.js,我知道路由用于将URL映射到模板,但显然您可以使用this.route或this.resource定义路由 App.Router.map(function() { this.route("about", { path: "/about" }); this.route("favorites", { path: "/favs" }); }); App.Router.map(function() { this.resource('posts', { path: '/posts' }, f
App.Router.map(function() {
this.route("about", { path: "/about" });
this.route("favorites", { path: "/favs" });
});
App.Router.map(function() {
this.resource('posts', { path: '/posts' }, function() {
this.route('new');
});
});
如果要定义路由的子例程,是否只使用this.resource,或者是否有其他我不了解的理由
如果要定义路由的子例程,是否只使用this.resource,或者是否有其他我不了解的理由
这是基本的想法
- 资源=父(通常为名词)
- route=child(通常是动词)
App.Router.map(function() {
this.resource("about", { path: "/about" });
});
你会得到这样的结果:
App.Router.map(function() {
this.resource('about', { path: '/about' }, function() {
this.route('index');
});
});
这在余烬3.x中被折旧。没有更多的
此.resource()
谢谢!:)但是您不能在资源下定义资源,对吗?如果您希望您的URL看起来像/contacts//edit
(如此处)?您应该能够做到--“contacts”将是/(例如由ArrayController支持)下的一个资源,“:contact_id”将是另一个具有“edit”路由的资源(由ObjectController支持)。检查文档中的嵌套资源部分: