我想從視圖對象上設置的底層對象獲取記錄ID,所以我可以將它設置在視圖的HTML包裝上。這裏就是我想:如何訪問Ember.View中的上下文?
// Row in record editing table view.
views.RecordActionTableRowView = Ember.View.extend({
// Does not work.
attributeBindings: ['record_id:data-record-id'],
templateName: 'pult-record-action-table-row',
init: function() {
console.log(this);
// Does not work either. Undefined.
console.log(this.get('record_id'));
// Does not work either. Undefined.
console.log(this.record);
return this._super();
}
});
這種觀點是從模板調用,所以它自己的模板中包含了正確的數據,但我無法找到它的視圖代碼內。有什麼建議麼?
能爲您提供的jsfiddle說明問題了嗎?從發佈的代碼中,似乎不可能知道發生了什麼。你的模板是什麼樣的?記錄是如何設置的?你可以用這個作爲起點:http://jsfiddle.net/pangratz666/DvdVH/ – pangratz
那麼,確切的例子在這裏幾乎沒有關係。我只是想弄清楚是否有一種通用的方式來從視圖中訪問模板上下文。關於它的文檔沒有任何內容。據說在視圖上有一個上下文屬性,但這也是未定義的。 – mikl
你可以先調用_super(),然後是日誌? –