Javascript Can';t在onRendered函数中设置ReactiveDict变量
为什么这会给我一个Javascript Can';t在onRendered函数中设置ReactiveDict变量,javascript,meteor,Javascript,Meteor,为什么这会给我一个类型错误:无法读取未定义的属性“set” Template.something.onCreated(function() { this.templateDictionary = new ReactiveDict(); }); Template.something.onRendered(function() { Template.templateDictionary.set( 'showExtraFields', true ); }); Template.so
类型错误:无法读取未定义的属性“set”
Template.something.onCreated(function() {
this.templateDictionary = new ReactiveDict();
});
Template.something.onRendered(function() {
Template.templateDictionary.set( 'showExtraFields', true );
});
Template.something.helpers({
anything: function() {
var result = Template.instance().templateDictionary.get( 'showExtraFields' );
console.log(result);
}
});
您的
onRendered
函数需要修复:
Template.something.onRendered(function() {
Template.instance().templateDictionary.set( 'showExtraFields', true );
});