ember.js connectController() [英] ember.js connectControllers()
问题描述
如果您有两个不同的页面(称为他们的家庭和帖子)共享ALMOST完全相同的内容和功能,最好的方式绑定到另一个?
If you have 2 different pages (call them home and posts) that share ALMOST exactly the same content and functionality, how is the best way to bind one to the other?
在此小提琴中,我将一个视图的内容与其他内容相关联通过直接在路由器中设置它:
In this fiddle I have associated the content of one view to the content of the other by setting it directly in the router like this:
Router: Ember.Router.extend({
root: Ember.Route.extend({
//transitions
home: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
var posts = router.get('postsController.content');
router.get('homeController').set('content', posts);
router.get('applicationController').connectOutlet('home');
},
}),
//posts and other states
})
})
但是,如果帖子内容可以,我真的不需要在家里更新内容,但是如果我这样做,会吗?
But: I don't really need the home content to update on the fly if the posts content does, but if I did, would it?
还有什么其他的方法?是否可以使用connectController(),然后使用WHERE?以下是我的错误尝试:另一个小提琴
What other way is there? Is it possible to use connectControllers() and then WHERE should it be used? Here is my -failed- attempt: another fiddle
home: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.get('homeController').connectControllers('posts');
router.get('applicationController').connectOutlet('home');
},
})
推荐答案
您可以使用模板
helper。
You could use the template
helper.
<script type="text/x-handlebars" data-template-name="posts">
<div class="right"><h2>posts page</h2>
{{template "posts-details"}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="posts-details">
{{#each post in content}}
<article>
<h3><a {{action "doPost" context="post"}} {{bindAttr id="post.id"}}>{{post.title}}</a></h3>
<p>{{post.date}}</p>
</article>
{{/each}}
</script>
查看您的更新小提琴
这篇关于ember.js connectController()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!