开发者

Where does Backbone.js fit in a webapp

I am creating a shopping wishlist webapp where user can store a bunch of products and manage them using lists and tags. My application is not a one page webapp, so I am wondering whether or not I should be using a code structuring app like Backbone.js?

Consider the new twitter analogy. I 开发者_StackOverflow社区want to handle the delete tweet, favorite a tweet, retweet using ajax/rest calls+dom manipulation but handle the change of displays like timeline, mentions etc using normal http request/response - complete page rendering.

  • In this case, how will I be leveraging the Models, Collections part of Backbone? When the page loads, there is no data for Models, Collections...the page is rendered using php+html coding.
  • Does using only the "View" suffice for my needs since I need to handle lots of element state changes? What about the ajax/rest requests.


I guess it's easy to fall victim to wanting to use Backbone on every project (—it is pretty sweet), but in the end the Model/Collection layer is it's real strength IMO. A few details aside, the view layer doesn't do much more than event delegation which can be achieved using "plain" jQuery as well.

Having said that, it might make good sense to use Backbone's Model/Collection layer as well in your case: Simply print the data used in your view as JSON in the header and initialize your Collection with it or even parse the view. — Backbone assists you with both.

I'm using the following rule of thumb: "If you find yourself appending to a longer and longer list of separate AJAX calls wrapped in event handlers for many different elements on your page during development, Backbone might be the answer." (If your server side implementation is RESTful.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜