0

Ember.CollectionViewの仕組みを理解しようとしていますが、 ArrayControllerのコンテンツをDOM に表示する際に基本的な問題が発生しています。ここに私の小さなjsfiddle実験がありますので、自分の目で確かめてください。コーヒースクリプトは次のとおりです。

window.App = Ember.Application.create()
window.App.initialize()

App.Item = Em.View.create
  tagName:'li'

  willInsertElement: () ->
  console.log "I **WILL** indert the element", this.$()

  didInsertElement: () ->
    console.log "I **DID** insert the element", this.$()

  template: Ember.Handlebars.compile("~~ {{view.content.title}} ~~")

App.items = Em.ArrayController.create()

App.items.set('content',[
    Em.Object.create({title:"AN"}),
    Em.Object.create({title:"Epic"}),
    Em.Object.create({title:"View"})
  ])

App.epicView = Ember.CollectionView.create
  classNames: ['epic-view']
  contentBinding: 'App.items'
  itemViewClass: 'App.Item'

App.epicView.appendTo('body')

そのフィドルの出力でわかるように、リスト内のオブジェクトのタイトルにアクセスして表示する方法を理解できませんでした。への呼び出しを使用してボディにビューを追加するとApp.epicView.appendTo('body')、3 つのオブジェクトを反復しているように見えますが、何も出力されません。

ここで何が欠けているのですか?

ps: 私はEmber 1.0preを使用しています

4

1 に答える 1

2

私は単に次のようなことをします: http://jsfiddle.net/Sly7/nevW2/67/

ビューをインスタンス化する (create を使用) のではなく、(extend を使用して) ビューを宣言する

于 2012-09-21T23:08:50.783 に答える