{{outlet}}、{{view}}、{{render}} 和 {{control}} 助手 [英] {{outlet}}, {{view}}, {{render}}, and {{control}} helpers
问题描述
我正在尝试组合一个简单的主细节 Ember 应用程序.一侧的目录树和另一侧的文件列表.
I am trying to put together a simple master-details Ember app. Directory tree on one side and file list on another.
Ember 提供了很少的帮助器来将上下文渲染到视图中.我可以将其中的哪些用于:
Ember offers few helpers to render context into a view. Which of them I can use for:
- 目录树的子树.
- 详细信息列表.
事实上,如果有人能指出我能读到的关于{{render view}}
、{{view view}}
之间的区别的任何文档,那将会非常有帮助code> 和 {{control view}}
助手以及如何正确使用它们.
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.
非常感谢!
推荐答案
{{view "directory"}}
在当前控制器的上下文中呈现视图.
{{view "directory"}}
renders the view within the context of the current controller.
{{render "directory"}}
在单例 的上下文中使用模板
directory
渲染视图 App.DirectoryView
App.DirectoryController
{{render "directory"}}
renders the view App.DirectoryView
with template directory
within the context of the singleton App.DirectoryController
{{control directory}}
的行为方式与 render
相同,只是它每次渲染时都会创建一个 App.DirectoryController
的新实例(与每次使用相同控制器实例的 render
不同).
{{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).
最后两个助手相对较新,因此没有太多关于它们的文档.您可以在此处找到{{view}}
文档.
The last two helpers are relatively new, so there isn't much documentation about them. You can find {{view}}
documentation here.
现在看看您的用例,我认为您不需要任何这些助手.只需使用嵌套路由和 {{outlet}}
助手,它应该可以正常工作.
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.
这篇关于{{outlet}}、{{view}}、{{render}} 和 {{control}} 助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!