Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ember.js中的路由结构_Javascript_Ember.js - Fatal编程技术网

Javascript ember.js中的路由结构

Javascript ember.js中的路由结构,javascript,ember.js,Javascript,Ember.js,我正试图了解Ember.js,我有一个CRUD Ember应用程序,目前有两个模型-user和subject。用户可以与许多主题关联。我的router.js如下所示: App.Router.map(function(){ this.resource('users', function(){ this.resource('user', { path:'/:user_id' }, function(){ this.route('edit'); }); this

我正试图了解Ember.js,我有一个CRUD Ember应用程序,目前有两个模型-
user
subject
。用户可以与许多主题关联。我的router.js如下所示:

App.Router.map(function(){
  this.resource('users', function(){
    this.resource('user', { path:'/:user_id' }, function(){
      this.route('edit');
    });
    this.route('create');
  });

  this.resource('subjects', function(){
    this.resource('subject', {path: '/:subject_id'}, function(){
        this.route('edit');
    });
    this.route('create');
  });

});
每个主题都有许多类别,这些类别也将具有CRUD功能,因此我现在需要实现一个
类别
模型。我的问题是,对类别的路由进行建模的最有效方法是什么?我应该将其定义为单独的路由结构还是
主题中的资源
路由?我尝试了后者,但它弄乱了我的整个应用程序,没有在浏览器中呈现任何内容。非常感谢您对示例的任何建议/链接

编辑:类别路由

App.CategoriesRoute = Ember.Route.extend({
  model: function(){
    return this.store.find('category');
  }
});

App.CategoryRoute = Ember.Route.extend({
  model: function(params) { 
    return this.store.find('category', params.category_id);
  }
});

你能告诉我你是如何定义分类路线和访问哪个url的吗?我不知道我访问哪个url是什么意思。你在浏览器中得到的url。一个分类可以属于多个主题吗?如果类别和主题具有多对多关系,则单独的路由结构会更好。一个类别只能属于一个主题,但一个主题可以有多个类别。我现在已经单独实现了它们,这是否允许类别的CRUD功能?当然,如果您愿意,您可以在资源下面定义CRUD路由,并且我在模板中引用的这些路由与其他路由相同吗?
App.Router.map(function(){
  this.resource('users', function(){
    this.resource('user', { path:'/:user_id' }, function(){
      this.route('edit');
    });
    this.route('create');
  });

  this.resource('subjects', function(){
    this.resource('subject', {path: '/:subject_id'}, function(){
        this.route('edit');
        this.resource('categories', function(){
          this.resource('category', , {path: '/:category_id'})'
        });
    });
    this.route('create');
  });

});