2

同じCollectionViewコードが9.8.1および最新で実行されている2つの例があります。9.8.1バージョンは機能します:http://jsfiddle.net/ethan_selzer/kcjzw/230/。ただし、最新バージョンはそうではありません:http: //jsfiddle.net/kcjzw/232/

最新のビルドでEmber.CollectionViewAPIに重大な変更はありますか?または、CollectionViewの現在のビルドに問題がありますか?

ありがとう、イーサン

4

1 に答える 1

5

You can either do what Kristofor Selden suggested in this fiddle http://jsfiddle.net/krisselden/6fAHZ/ (bind the content array in the itemViewClass) or you can do it as follows:

Fiddle: http://jsfiddle.net/ppanagi/WhGjR/

App = Ember.Application.create();

App.collectionView = Ember.CollectionView.create({

    content: [
      { key: 'value one' },
      { key: 'value two' }
    ],

    itemViewClass: Ember.View.extend({
      template: Ember.Handlebars.compile('{{view.content.key}}')
    })
});

App.collectionView.append();​

The default context of templates are now controller variables, so {{foo}} will return the value of the controller variable foo. If you need the value of bar variable of the View, use {{view.bar}}.


Follow up: Yet another way to change the context is to use {{with}}:

App.collectionView = Ember.CollectionView.create({
  template: Ember.Handlebars.compile('{{#with view}} {{content.key}} {{/with}}')
});
于 2012-07-11T22:34:30.397 に答える