简体   繁体   English

Backbone.js中的模板分层

[英]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. 我主要接受过React方面的培训,所以据我所知,骨干网有些过时,但是我正在接受求职面试的挑战。

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. 给了我一个项目文件,该文件的集合已经给了我,并有6个博客帖子。

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. 因此,在react中,您只需创建两个组件(一个列表容器和一个列表项),然后使用该容器渲染该列表项组件,然后在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? 模板或多或少与React中的组件等效吗?

Can you render a template within another template? 您可以在另一个模板中渲染一个模板吗?

Unlike react - which is a rendering engine, backbone is a framework, not a rendering engine. 与react-渲染引擎不同,主干是框架而不是渲染引擎。 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. 例如,如果您使用soy模板,则可以从另一个调用一个模板。 Or maybe you can use react itself with Backbone as template engine. 或者,您可以将自身与Backbone一起用作模板引擎。

Is a template more or less the equivalent of a component in react? 模板或多或少与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. 否。等效的组件将是Backbone.View因为据我所知,react组件具有其自身的行为,因为骨干模板尚不清楚。 The behavior is handled by the view rendering the template. 该行为由呈现模板的视图处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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