【问题标题】:TagsIndexRoute is never called TagsRoute is EmberjsTagsIndexRoute 永远不会被称为 TagsRoute 是 Emberjs
【发布时间】:2013-12-27 21:42:47
【问题描述】:

我正在尝试从这里 Original 部分复制用于学习清酒的示例

我的 jsbin 是 MY JSBIN 我的帖子路线是

App.PostsIndexRoute = Ember.Route.extend({
  model: function() {
     return this.modelFor('posts');
  }
}); 
App.PostsRoute = Em.Route.extend({
  model: function(){
    return this.store.findAll('post');
  } 
});

和我的标签路由完全一样。

App.TagsIndexRoute = Em.Route.extend({ model:function(){ 返回 this.modelFor('tags'); } });

App.TagsRoute = Em.Route.extend({ model: function(){ 返回 this.store.findAll('tag'); } });

如果我的数据模板名称是 data-template-name="tags",我可以显示数据 我无法使用 data-template-name="tags/index" 显示数据

我的路由器地图是这样的

App.Router.map(function() {
  // put your routes here
  this.route('about');
  this.resource('posts',{path:'/posts'},function(){
    this.route('post',{path:':id'});
  });

  this.resource('tags',{path:'/tags'});
});

它只是默默地失败,没有错误消息。如果在 IndexRoute 我从 transitionTo('tags') 更改为 transitionTo('posts') 一切正常,不知道我哪里出错了。

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    有一个记录在案的错误/功能,如果您的资源没有传递函数参数,它将不会创建索引路由

     this.resource('tags',{path:'/tags'}, function(){});
    

    https://github.com/emberjs/ember.js/issues/3995#issuecomment-31200805

    注意:如果您使用 this.resource 定义资源并且不提供函数,则不会创建隐式 resource.index 路由

    http://emberjs.com/guides/routing/defining-your-routes/

    【讨论】:

    • 我很抱歉问了一些我可以通过更多关注来解决的问题。无论如何,谢谢。
    • 不用担心,我提交了错误但不知道,这是一个有效的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-18
    • 2012-10-27
    • 2013-10-12
    • 2013-08-21
    • 2021-10-25
    相关资源
    最近更新 更多