ember.js + 把手:渲染 vs 出口 vs 局部 vs 视图 vs 控制 [英] ember.js + handlebars: render vs outlet vs partial vs view vs control

查看:14
本文介绍了ember.js + 把手:渲染 vs 出口 vs 局部 vs 视图 vs 控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对每一个都有零星的解释,但我仍然不是 100% 清楚差异&用法.有人可以给我一个并排比较吗?

There are scattered explainations of each around, but I'm still not 100% clear on the differences & usage. Could someone give me a side-by-side comparison?

{{outlet}}
{{outlet NAME}}
{{render}}
{{partial}}
{{view}}
{{control}}

注意:这篇文章对局部渲染与渲染非常有帮助>

Note: this post was very helpful with partial vs render

推荐答案

它们都是模板助手,具有 emberjs 指南中描述的以下主要特征.(http://emberjs.com/guides/templates/rendering-with-helpers/)

They are all template helpers with the following main characteristics as described in emberjs guides. (http://emberjs.com/guides/templates/rendering-with-helpers/)

1.{{outlet}} - 根据路由器确定的路由呈现模板.根据路由使用相应的控制器和视图.这在基于路由渲染内容时很有用,这是最常见的情况.

1.{{outlet}} - Renders a template based on the route determined by the router. Based on the route the corresponding controller and view are used. This is useful when rendering contents based on the route, which is the most common case.

2.{{outlet NAME}} - 提供在路由中指定渲染内容的准确位置的能力.在尝试从多个模板为一个路由渲染内容时很有用.

2.{{outlet NAME}} - Provides the ability to specify in the route where exactly to render the content. Useful when trying to render contents from more than one templates for a route.

3.{{render}} - 与 outlet 类似,但控制器/视图/模型可以直接或间接从助手指定.当需要从多个模板渲染内容时很有用,并且能够覆盖上下文(视图/控制器)和模型.如果指定了模型,它将使用相应控制器的唯一实例,否则将使用单例实例.当需要覆盖路由的上下文和模型时很有用,同时呈现多个模板内容.

3.{{render}} - Similar to outlet but the controller/view/model can be specified directly or indirectly from the helper. Useful when required to render content from more than one template with the ability to override the context (view/controller) and model. If model is specified it uses a unique instance of the corresponding controller, otherwise it will use the singleton instance. Useful when required to overide the route's context and model, while rendering multiple template contents.

4.{{control}} - 像渲染一样工作,除了它为每次调用使用一个新的控制器实例,而不是重用单例控制器.当使用 render 时,不可能在不指定模型的情况下为同一路由使用多个渲染,在这种情况下应该使用 control.用于为呈现的每个模板内容支持控制器的新实例.

4.{{control}} - Works like render, except it uses a new controller instance for every call, instead of reusing the singleton controller. When using render it is not possible to use multiple render for the same route without specifying the model, for that case the control should be used. Useful to support new instances of a controller for every template content rendered.

更新: 控制助手已被删除 https://github.com/emberjs/ember.js/commit/86eecd7ef7cdc7d2ea6f77b3a726b293292ec55d .

Update: Control helper has been removed https://github.com/emberjs/ember.js/commit/86eecd7ef7cdc7d2ea6f77b3a726b293292ec55d .

5.{{partial}} - 将要呈现的模板作为参数,并就地呈现该模板.它不会改变上下文或范围.它只是将给定的模板放到当前范围内.所以没有为部分指定视图类.当需要将模板分解为模板模块时很有用,以实现更好的控制或可重用性,而无需创建任何视图类.

5.{{partial}} - Takes the template to be rendered as an argument, and renders that template in place. It does not change context or scope. It simply drops the given template into place with the current scope. So no view class is specified for the partial. Useful when it is required to break a template into template modules, for better control or reusability, without creating any view classes.

6.{{view}} - 这与部分类似,但提供了一个视图类.视图类指定要使用的模板.在将模板分解为模块但需要视图类时很有用,例如用于事件处理.

6.{{view}} - This works like partial but a view class is provided. The view class specifies the template to be used. Useful when breaking a template into modules but requiring a view class e.g. for event handling.

7.{{#view}} - 还有视图助手的块形式,它允许指定与父视图模板内联的子视图模板.(http://emberjs.com/guides/views/inserting-views-in-templates/)

7.{{#view}} - There is also the block form of the view helper, which allows specifying the template of the child view inline with the parent view template. (http://emberjs.com/guides/views/inserting-views-in-templates/)

这篇关于ember.js + 把手:渲染 vs 出口 vs 局部 vs 视图 vs 控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆