将controller属性传递给组件ember.js

时间:2014-03-25 08:51:40

标签: ember.js

是否有办法将属性从控制器传递给组件,而不是直接传递给模型。在这种情况下,模型返回一个数组,因此我定义了一个从ArrayController扩展的控制器。现在我希望blog-post组件的每个实例都有一个名为name的属性,该属性从索引控制器传递。如何将此属性传递给组件。此外,如果我想为单个控制器更改此属性,如何稍后获取单个控制器。

<script type="text/x-handlebars" data-template-name="index">
{{#each}}
{{#blog-post title=title name=name}}
  {{body}}
{{/blog-post}}
{{/each}}
</script>

<script type="text/x-handlebars" data-template-name="components/blog-post">
<article class="blog-post">
<h1>{{title}}</h1>
<h2>{{name}}</h2>
<p>{{yield}}</p>
<p>Edit title: {{input type="text" value=title}}</p>
</article>
</script>


App = Ember.Application.create();

posts = [{
title: "Rails is omakase",
body: "There are lots of à la carte software environments in this world."
}, {
title: "Broken Promises",
body: "James Coglan wrote a lengthy article about Promises in node.js."
}];

App.IndexRoute = Ember.Route.extend({
model: function() {
return posts; 
}
}); 
App.IndexController=Ember.ArrayController.extend({
name:'Pranava'
});

0 个答案:

没有答案