ember.js + handlebars:render vs outlet vs partial vs view vs control [英] ember.js + handlebars: render vs outlet vs partial vs view vs control

查看:122
本文介绍了ember.js + handlebars:render vs outlet vs partial vs view vs control的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都有分散的说明,但我仍然没有百分之百地澄清差异。用法。有人可以给我一个并排的比较吗?

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

注意:此信息对于部分vs渲染非常有帮助

解决方案

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



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



2。 {{出口NAME}} - 提供在完全呈现内容的路线中指定的功能。 尝试从路由的多个模板中呈现内容时有用



3。 {{render}} - 类似于 outlet ,但是可以从帮助器直接或间接指定controller / view / model。当需要使用多个模板渲染内容并具有覆盖上下文(视图/控制器)和模型的能力时很有用。如果指定了模型,则使用相应控制器的唯一实例,否则将使用单例实例。



4。 {{控制}} - 像渲染一样工作,除了它为每个调用使用一个新的控制器实例,而不是重新使用单例控制器。当使用 render 时,不能在不指定模型的情况下为同一路径使用多个渲染,对于这种情况,控件应该使用。 控件助手已被删除 https://github.com/emberjs/ember.js/commit/86eecd7ef7cdc7d2ea6f77b3a726b293292ec55d



5。 {{partial}} - 将模板渲染为参数,并将该模板呈现到位。它不会改变上下文或范围。它简单地将给定的模板放在当前范围内。所以没有为partial指定视图类。



code> {{view}} - 这样做与部分类似,但提供了一个视图类。视图类指定要使用的模板。 将模板拆分为模块但需要视图类时很有用对于事件处理。



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


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

解决方案

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}} - 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}} - 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}} - 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}} - 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.

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

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}} - 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}} - 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 + handlebars:render vs outlet vs partial vs view vs control的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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