Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a link without preloading the model?

Tags:

ember.js

Right now, we're building our links like that:

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

That generates a link which looks like /comments/45.

Unfortunately, that only works when we preload the comment - even though we already have the ID of the comment. Is it possible without preloading the comment?

Something that might look like:

<a {{action showComment comment_id href=true}}>Show</a>
like image 737
kraftwer1 Avatar asked Feb 20 '13 13:02

kraftwer1


1 Answers

What is the actual question here? This is not quite clear to me.

So your current action handler looks like this:

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

Now your desired solution could look like this:

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

And the corresponding handler:

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
}

Would this work in your case? Or did you intend something else?


UPDATE: OP would like have all Data Handling in the route Your Route should handle the action "showCommentById" that i did propose before:

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

So actually you are free to decide where to handle actions in your app.

like image 120
mavilein Avatar answered Nov 15 '22 10:11

mavilein