我在“emberjs.com”上关注了一个不太顺利的例子。我的应用程序中有一个“GuestController”和“GuestView”。我想使用“{{#view}} & {{#each}} 从“GuestView”输出一个名为“guests”的对象。我正在关注这个在线示例:
http://emberjs.com/documentation/#toc_displaying-a-list-of-items
小提琴:http: //jsfiddle.net/exciter/MjA5A/8/
这是代码:
应用程序代码:
$(function(){
App = Ember.Application.create({
ready: function(){
//alert("APP INIT");
}
});
App.ApplicationController = Ember.Controller.extend();
App.ApplicationView = Ember.View.extend({
templateName: "application",
classNames: ['']
});
App.GuestController = Ember.Controller.extend();
App.GuestView = Ember.View.extend({
guests: [{name:"The Doctor" },
{name:"The Scientist" },
{name:"The Maestro"}]
});
App.initialize();
});
HTML:
<script type="text/x-handlebars" data-template-name="application">
{{#each App.GuestController}}
{{#view App.GuestView}}
{{guests}}
{{/view}}
{{/each}}
</script>