使用ember.js路由名称
我有一个这样的路由器使用ember.js路由名称,ember.js,Ember.js,我有一个这样的路由器 App.Router.map(function () { this.route("about"); this.resource("invoices", { path: "/invoices" }, function () { this.resource("invoices.show", { path: "/:id" }); this.resource("invoices.update", { path: "/:id/edit"
App.Router.map(function () {
this.route("about");
this.resource("invoices", { path: "/invoices" }, function () {
this.resource("invoices.show", { path: "/:id" });
this.resource("invoices.update", { path: "/:id/edit" });
this.route("create");
});
});
为了生成到各种路线和资源的链接,我有这个
<nav>
{{#linkTo "invoices.index"}}Invoices{{/linkTo}}
{{#linkTo "invoices.show" 1}}Invoice{{/linkTo}}
{{#linkTo "invoices.create"}}New invoice{{/linkTo}}
</nav>
而且它会自动为资源名添加前缀,因为它们嵌套在invoices资源中。是吗?是的,嵌套资源可以堆叠它们的名称,并且您应该能够使用点表示法引用嵌套路由 但是,您需要执行以下操作:
this.resource("invoices", { path: "/invoices" }, function () {
// invoices.show
this.resource("show", { path: "/:id" }, function() {
// invoices.show.update
this.route("update", { path: "/edit" });
});
// invoices.create
this.route("create");
});
因为更新操作依赖于提供给显示路由的对象
基本上,依赖于相同或父路由中使用的资源子集的嵌套元素应定义为资源映射。叶节点可以定义为基本路由。是的,嵌套资源可以堆叠它们的名称,并且您应该能够使用点符号引用嵌套路由 但是,您需要执行以下操作:
this.resource("invoices", { path: "/invoices" }, function () {
// invoices.show
this.resource("show", { path: "/:id" }, function() {
// invoices.show.update
this.route("update", { path: "/edit" });
});
// invoices.create
this.route("create");
});
因为更新操作依赖于提供给显示路由的对象
基本上,依赖于相同或父路由中使用的资源子集的嵌套元素应定义为资源映射。叶节点可以定义为基本路由