javascript - 如何在 Ember.js 中重复资源

标签 javascript ember.js

我有一个使用 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/

相关文章:

javascript - 拒绝通过在菜单周围单击来激活菜单

javascript - 在高阶 rxjs observable 中收集当前不完整的 observable

javascript - 用于替换单个反斜杠的正则表达式,不包括后跟某些字符的反斜杠

ember.js - 使用 ember-simple-auth 和 torii,尽管服务器响应成功,但模式永远不会关闭, session 也永远不会更新

ember.js - Ember : Access sideloaded model relationship data in template

javascript - Chrome浏览器排序字符串时如何使用localeCompare?

javascript - React-native - 使用已转换为 URL 的 Blob 填充图像

javascript - 带有 node.js 的前端 javascript 框架

javascript - Ember.js 如何引用 Grunt.js 预编译的 Handlebars 模板?

ember.js - 服务未定义?