我有一个使用 url 中的页面标题的页面资源。
App.Router.map(function () {
this.resource('page', {
path: '/:page_id'
});
});
App.PageRoute = Ember.Route.extend({
serialize: function(model) {
return { page_id: model.title};
}
});
这在 jsbin 中运行良好.但是,我希望像这样在 url 中嵌套子页面:
localhost/#/main_page/sub_page
我试图制作一个子资源(jsbin),但我不确定这是否是正确的方法。
App.Router.map(function () {
this.resource('page', {path: '/:page_id'},
this.resource('subpage', {path: '/:page_id/:subpage_id'}));
});
在我的尝试中有两个主要问题:我必须重复我的页面 View 并且它没有在 url 中保留父页面。我得到:
localhost/#/undefined/sub_page
我的方向是否正确?这可以仅用一种资源来完成吗?
提前致谢!
最佳答案
你考虑过嵌套资源吗?
App.Router.map(function () {
this.resource('page', {path: '/:page_id'}, function(){
this.resource('subpage', {path: '/:subpage_id'});
});
});
这至少会启用您要求的 URL 结构,但我不太确定您的要求。
关于javascript - 如何在 Ember.js 中重复资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20435111/