{{outlet}},{{view}},{{render}}和{{control}}助手 [英] {{outlet}}, {{view}}, {{render}}, and {{control}} helpers

查看:62
本文介绍了{{outlet}},{{view}},{{render}}和{{control}}助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个简单的大师​​细节Ember应用程序。目录,另一方面的文件列表。



Ember提供了很少的帮助者将上下文呈现到视图中。我可以使用哪些:


  1. 目录树的子树。

  2. 详细信息列表。

事实上,如果有人可以指向任何文档,我可以阅读有关 {{render view}} {{view view}} {{control view}} helpers以及如何正确使用它们。



非常感谢!

解决方案

{{viewdirectory}} 在当前控制器的上下文中呈现视图。



{{renderdirectory}} 使用模板 App.DirectoryView >目录在单例的上下文 App.DirectoryController



{{控制目录}} 的行为方式与 render 的方式相同,只创建一个新的实例App.DirectoryController 每次渲染(不同于 render whic每次使用相同的控制器实例。



更新2014年2月18日: {{control}} 删除。



最后两个帮助器是比较新的,所以没有太多关于它们的文档。您可以在这里找到 {{view}} 文档此处



现在看看你的用例,我不认为你需要任何这些帮助者。只需使用嵌套路由和 {{outlet}} 助手,它应该只是工作。

 code> App.Router.map(function(){
this.resource('directories',function(){
this.resource('directory',{path:'/:directory_id '},function(){
this.route('files');
});
});
});

您可以在本指南



更新: {{render}} 现在,如果您传递模型,则每次都会创建一个新的实例。


I am trying to put together a simple master-details Ember app. Directory tree on one side and file list on another.

Ember offers few helpers to render context into a view. Which of them I can use for:

  1. Subtrees of the directory tree.
  2. Details list.

In fact, would be very helpful if someone can point me to any docs I can read about the difference between {{render view}}, {{view view}} and {{control view}} helpers and how to use them properly.

Thanks a lot!

解决方案

{{view "directory"}} renders the view within the context of the current controller.

{{render "directory"}} renders the view App.DirectoryView with template directory within the context of the singleton App.DirectoryController

{{control directory}} behaves the same way as render only it creates a new instance of App.DirectoryController every time it renders (unlike render which uses the same controller instance every time).

Update 18 Feb 2014: {{control}} has been removed.

The last two helpers are relatively new, so there isn't much documentation about them. You can find {{view}} documentation here.

Now looking at your use case, I don't think you need any of these helpers. Just use nested routes and the {{outlet}} helper and it should just work.

App.Router.map(function(){
  this.resource('directories', function() {
     this.resource('directory', { path: '/:directory_id'}, function() {
       this.route('files');
     });
  });
});

You can build on that following this guide.

UPDATE: {{render}} now creates a new instance every time if you pass a model.

这篇关于{{outlet}},{{view}},{{render}}和{{control}}助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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