0

启动 DOM 时出现“找不到模板”错误。这是我的代码:

//javascripts/app/app.js
MyApp = Ember.Application.create();

MyApp.store = DS.Store.create({
  revision: 4,
  adapter: DS.RESTAdapter.create({ bulkCommit: false })
});

//javascripts/app/models/event.js
MyApp.Event = DS.Model.extend({
    id: DS.attr('number'),
    league_id: DS.attr('number')
});

//javascripts/app/controllers/event.js
MyApp.eventsController = Ember.ArrayController.create({
      content: [],

      init: function() {
        this.content = jQuery.get('events.json');
      }
});

//javascripts/app/views/events/list.js
MyApp.EventListView = Ember.View.extend({
  templateName: 'app/templates/events/list',
  eventsBinding: 'MyApp.eventsController'
});

//javascripts/app/templates/events/list.handlebars
{{#each events}}
    {{view MyApp.EventListView eventsBinding='this'}}
{{/each}}

//app/views/events/index.html.erb
<script type='text/x-handlebars'>
  {{ view MyApp.EventListView }}
</script>

我尝试了此问答中建议的修复方法之一,但无法让它为我工作。我做错了什么?

4

1 回答 1

2

对于您的错误,如果整个代码都在这里,那么您错过了<script>车把list模板中的标签:

<!-- conforms to MyApp.EventListView templateName property -->
<script type='text/x-handlebars' data-template-name="list">
   {{#each events}}
<!-- you dont have to insert {{view MyApp.EventListView eventsBinding='this'}} 
here, as I think you want to manipulate an event -->
       {{league_id}} 
   {/each}}
</script>

顺便说一句,你的控制器的 init 方法是错误的:

MyApp.eventsController = Ember.ArrayController.create({
  content: [],

  init: function() {
    this._super(); // when you override init(),
                   // you have to call the super class init().

    this.set('content', jQuery.get('events.json')); 
    // that the way to set properties with ember. You have to use this.
  }
});

如果它没有帮助,正如@Rajat 建议的那样,请发布完整代码的 jsfiddle。

于 2012-08-03T07:14:13.823 回答