[英]Get template variable inside onRendered in Meteor
我有一個模板settings
,其中有一個自動表單。
我在onRendered
函數中的自動表單中添加了一個掛鈎
Template.settings.onRendered( () => {
AutoForm.addHooks( 'editForm', {
onSuccess: function( formType, result ) {
//
}
} );
} );
我如何在onSuccess
內部通過Template.settings.helpers
在模板中填充變量?
我已經嘗試過Template.instance().variableName
,但是找不到。
從Meteor文檔中:
在回調的主體中,這是一個模板實例對象,對於模板的這種出現是唯一的,並且在重新渲染期間保持不變。 使用onCreated和onDestroyed回調對對象執行初始化或清理。
http://docs.meteor.com/#/full/template_onRendered
但我認為你需要使用的function
,而不是一個ES2015箭頭功能或this
將無法達到預期。
另外,您需要添加以下行: const self = this;
然后,如果要在Autoform
函數中訪問self
,請使用self
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.