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>

このQ&Aで提案された修正の1つを試しましたが、うまく機能しませんでした。私が間違っていることは何ですか?

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 に答える