2012-07-11 43 views
2

我有兩個運行在9.8.1和最新版本下的CollectionView代碼的例子。9.8.1版本的工作原理是:http://jsfiddle.net/ethan_selzer/kcjzw/230/。但最新版本不:http://jsfiddle.net/kcjzw/232/最新版本中的Ember.CollectionView API是否有重大更改?

在最新版本中,Ember.CollectionView API是否存在重大更改?或者,CollectionView的當前版本有問題嗎?

感謝, 伊桑

+0

我想你應該問[問題](https://github.com/emberjs/ember。 js/issues?labels = question&page = 1&state = open)直接在存儲庫問題列表中,並從開發人員處獲得答案。 – MilkyWayJoe 2012-07-11 16:23:20

+1

感謝MilkyWayJoe。我按照你的建議在Ember回購中提交了這個問題。 – 2012-07-11 17:39:27

+1

Kristofor Selden在官方存儲庫問題跟蹤器上回答了此問題。以下是他的指導:默認上下文已從視圖更改爲控制器。你可以通過綁定來改變上下文,就像這樣http://jsfiddle.net/krisselden/6fAHZ/ – 2012-07-11 20:10:14

回答

5

你可以做什麼Kristofor塞爾登在這個小提琴http://jsfiddle.net/krisselden/6fAHZ/(在itemViewClasscontent數組綁定)建議,或者你可以如下做到這一點:

小提琴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();​ 

模板的默認上下文現在是控制器變量,所以{{foo}}將返回控制器變量foo的值。如果您需要查看的bar變量的值,請使用{{view.bar}}


追問:還有一種方法可以更改上下文是使用{{with}}

App.collectionView = Ember.CollectionView.create({ 
    template: Ember.Handlebars.compile('{{#with view}} {{content.key}} {{/with}}') 
}); 
+0

謝謝扎克。絕對是一個寶貴的貢獻。 – 2012-07-12 03:15:26

相關問題