meteor中钩子无功variables的变化值

我有

Template.templateName.onCreated(function() { this.variableName = new ReactiveVar; this.variableName.set(true); }); 

并在templateName我有一个autoform 。 提交autoform时,我需要设置被动variablesvariableNamefalse

我努力了

 AutoForm.hooks({ myForm: { onSuccess: function(operation, result) { this.variableName.set(false); }, } }); 

但是this.以后它不起作用this. 没有像helpers和events那样引用template templateName 。 如果我使用会话,它会起作用,因为它们不限于/限于特定的模板。

我能做些什么来改变autoform钩子中的无功variables?

我也试过了

 AutoForm.hooks({ myForm: { onSuccess: function(operation, result) { this.template.variableName.set(false); this.template.parent.variableName.set(false); this.template.parent().variableName.set(false); this.template.parentData.variableName.set(false); this.template.parentData().variableName.set(false); this.template.parentView.variableName.set(false); this.template.parentView().variableName.set(false); }, } }); 

当使用console.log(this.template)它打印一个对象。 如果我使用console.log(this.template.data)我会得到

 Object {id: "myForm", collection: "Meteor.users", type: "update", doc: Object, validation: "submitThenKeyup"…} 

我使用反应variablesvariableName来确定是否显示可编辑的窗体或用户的数据的良好呈现。 也许还有另一种更好的方法来做到这一点。

编辑onCreated:

 Template.templateName.onCreated(function() { this.variableName = new ReactiveVar(false); }); 

您可能需要添加一个帮助函数来获取Template实例:

 Template.templateName.helpers({ getVariableName: function() { return Template.instance().variableName.get(); } }); 

然后你可以在你的表单逻辑中调用

 AutoForm.hooks({ myForm: { onSuccess: function(operation, result) { Template.getVariableName.set(false); }, } }); 

MeteorChef有关于被动variables/字典反应variables的伟大文章。

如果人们偶然发现一个解决scheme,基于这个线程我能够访问父母Reactive Dict / Reactive Variable安装aldeed之后:template-extension像这样

 AutoForm.hooks({ postFormId: { //onSuccess hook of my post form onSuccess: function(formType, result) { this.template.parent().reactiveDictVariable.set('imgId', 'newValueSetOnSuccess'); //Or reactive var, and depending on your hierarchy //this.template.parent().parent().yourReactiveVar.set(undefined); } } }); 

这里是Html和JS供参考。

 <template name="postsTemplate"> {{#autoForm schema=postFormSchema id="postFormId" type="method" meteormethod="addPost"}} <!-- other autoform stuff --> This is reactive variable used in template -- {{imgId}} {{/autoForm}} </template> Template.postsTemplate.created = function() { //Using reactive-dict package here this.reactiveDictVariable = new ReactiveDict(); this.reactiveDictVariable.set('imgId', undefined); }; Template.posts.events( "change .some-class": function(event, template) { //other stuff template.postImgState.set('imgId', 'something'); }