这是我的代码。
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
{{#each model1}}
<li>title</li>
{{/each}}
</script>
和我的arraycontroller
App.IndexRoute = Ember.Route.extend({
});
App.IndexController = Ember.ArrayController.extend({
model1: function () {
return posts;
}
});
和我的Json
posts = [{
title: "Raja",
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." }];
请告诉我如果可以从控制器调用model1
答案 0 :(得分:1)
是的,但它需要是一个属性,而不是一个函数
App.IndexController = Ember.ArrayController.extend({
model1: function () {
return posts;
}.property()
});
但是如果它是一个模型,那么从路径返回它会更有意义,并在控制器中使用模型
App.IndexRoute = Ember.Route.extend({
model: function(){
return posts;
}
});
App.IndexController = Ember.ArrayController.extend();
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{#each item in controller}}
<li>{{item.title}}</li>
{{/each}}
</ul>
</script>