简体   繁体   中英

Layering templates in Backbone.js

I am primarily trained in React so backbone is a bit old-fashioned as far as I can tell, however I am doing a take-home challenge for a job interview.

The task is to build a blog post viewer in backbone and underscore.

I was given a project file with the collection already given to me with an object of 6 blog posts.

There is a container that the blog posts are rendered into. This should contain things like the total number of items, number of approved posts, rejected posts, and the list of blog posts, etc. There should also be a layer for the posts themselves, each containing a single line snippet of the text, date and time of post, social network type, etc.

So in react, youd just create two components (a list container and a list item) and youd render the list item component with the container then render the container in the html.

What is the best way to achieve this in backbone? Can you render a template within another template? Is a template more or less the equivalent of a component in react?

Can you render a template within another template?

Unlike react - which is a rendering engine, backbone is a framework, not a rendering engine. You can use any templating libraries with it. And the answer to this depends on what you use. For example if you use soy templates you can call one template from another. Or maybe you can use react itself with Backbone as template engine.

Is a template more or less the equivalent of a component in react?

No. the equivalent of a component would be a Backbone.View because as far as I know react components have their own behavior, for backbone template is an unknown. The behavior is handled by the view rendering the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM