簡體   English   中英

ember.js中的路由結構

[英]Routing structure in ember.js

我正在努力了解Ember.js,並且有一個CRUD ember應用程序,該應用程序當前具有兩個模型: usersubject 用戶可以與許多主題相關聯。 我的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功能,因此我現在需要實現一個categories模型。 我的問題是,為類別的路由建模最有效的方法是什么? 我應該將其定義為單獨的路由結構還是subjects路由中的資源? 我嘗試了后者,但它弄亂了我的整個應用程序,瀏覽器中沒有任何內容。 任何建議/鏈接到示例非常感謝。

編輯:類別路由

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);
  }
});
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');
  });

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM