我想从视图对象上设置的底层对象获取记录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(),然后是日志? –