如何访问 Ember.View 中的上下文?



我正在尝试从视图对象上设置的基础对象中获取记录 ID,以便我可以在视图的 HTML 包装器上设置它。这是我正在尝试的:

// 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();
}
});

此视图是从模板调用的,因此它自己的模板包含正确的数据,但我在视图代码中找不到它。有什么建议吗?

你可能想要this.get('context')this.get('content')。在某些情况下,在didInsertElement内检查这一点可能比在init中更好,以防视图是在设置context之前创建的。

我刚刚遇到同样的问题,试图访问文档中描述为模板变量在我的情况下,以下内容有效

this.get("templateData.keywords.myvarname")

相关内容

最新更新