Rails + Show Dynamic content with backbone.js -


i'm making api call using backbone model returns json list of posts.

each post dynamic can be
1. liked or unliked
2. commented or not commented
3. shared public or private or a group

now in backbone template while displaying posts, i'm doing if else conditions display dynamic content.

<% if(jsonresponse["like"] == true){ *>   <a href="/posts/1/like">like</a> <%} else %>   <a href="/posts/1/like">unlike</a> <% } %>  <% if(jsonresponse.target == 'public'){ *>   <a href="#">public</a> <%} else if(jsonresponse.target == 'private'){%>   <a href="#">private</a> <% } else if(jsonresponse.target == 'groups'){%>   <a href="#"><%= post.target.shared[0].displayname %></a> <% } %> 

is how should display dynamic content?
checking conditions in template right way it?

i know looks bit ugly there isn't wrong it. maybe split view 2 (like/unlike ... public/private/groups) when user clicks on like/unlike render above view.

in handlebars, use, tend write helpers functions abstracts these if/else , makes view clean. that's 1 option it's bit overkill if have 1 situation


Comments

Popular posts from this blog

shader - OpenGL Shadow Map -

stringtemplate - StringTemplate4 if conditional with length -