【发布时间】:2013-01-25 01:09:07
【问题描述】:
我对 Web 开发相当陌生,我正在尝试浏览 ember 文档示例。在我尝试使用 {{#each}} 助手之前,一切正常。我看不出我做错了什么,我是否使用了正确版本的车把?
这是在我的 html 中:
<div>First element</div>
<div id="second-placeholder"></div>
<div>Third element</div>
<script type="text/x-handlebars" data-template-name="second-item-template">
{{#each App.egosController}}
<h3>{{name}}</h3>
<p>{{id}} - {{type}}</p>
{{/each}}
</script>
这是我的控制器:
App.egosController = Ember.ArrayController.create({
content: [],
init: function(){
alert('Controller Initialised!');
}
});
App.egosController.set('content', [ego, alterEgo]);
Ember.View.create({
templateName: 'second-item-template'
}).appendTo('#second-placeholder');
jsfiddle 在这里:http://jsfiddle.net/VqgMk/64/
谢谢,
仁
【问题讨论】:
-
看看你的 JS 控制台:
ego没有定义。如果您将ego替换为myEgo,它将起作用 -
哦,感谢您指出这一点,这是漫长的一天,我想我已经尝试了一切......
-
我已经从上面的评论中做出了回答。很高兴为您提供帮助!