现在,我们正在构建这样的链接:
<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/