ember.js - 如何在不预加载模型的情况下建立链接?

标签 ember.js

现在,我们正在构建这样的链接:

<a {{action showComment comment href=true}}>Show</a>

这会生成一个类似于 /comments/45 的链接。

不幸的是,这仅在我们预加载评论时才有效 - 即使我们已经有了评论的 ID。是否可以不预加载评论?

可能看起来像这样:

<a {{action showComment comment_id href=true}}>Show</a>

最佳答案

这里的实际问题是什么?这对我来说不太清楚。

因此您当前的操作处理程序如下所示:

showComment : function(comment){
  //do your stuff with the model
}

现在您想要的解决方案可能如下所示:

<a {{action showCommentById comment_id href=true}}>Show</a>

以及相应的处理程序:

showCommentById : function(commentId){
  var comment = App.Comment.findById(commentId); // i assume you have this retrieval method or something like it
  this.showComment(comment);
},
showComment : function(comment){
  //do your stuff with the model
}

这对您的情况有用吗?或者您还有其他打算吗?

<小时/>

更新:OP 希望在 route 进行所有数据处理 您的路线应该处理我之前建议的操作“showCommentById”:

App.ArticlesRoute = Ember.Route.extend({
    events : {
        showCommentById : function(commentId){
            var comment = App.Comment.findByIds(commentId); // i assume you have this retrieval 
            this.transitionTo("root.articles.comment", comment);
        }
    }
});

所以实际上您可以自由决定在应用中的何处处理操作

关于ember.js - 如何在不预加载模型的情况下建立链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14980895/

相关文章:

ember.js - Ember : Accessing a nested object inside an #each loop

ember.js - Ember : Router pre and post hooks connectOutlets

javascript - 如何从 Ember 中的路由访问 Controller ?

unit-testing - Ember 测试 : Cannot read property 'createRecord' of null

javascript - 使用 {{#each x in model}} 语法时,Ember 的链接帮助程序未链接到正确的 URL?

ember.js - Ember 在转换后不渲染

javascript - Ember.js 推荐的从集合中删除项目并坚持到 REST 的方法

javascript - Ember-CLI 应用程序中的常规站点相关设置?

javascript - 从 API 获取 ember 组件中的数据

model - Ember Data - 在模板中呈现一对多