无法在onRendered-function中设置ReactiveDict-var

时间:2015-11-14 19:36:50

标签: javascript meteor

为什么这会给我一个TypeError: Cannot read property 'set' of undefined

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

1 个答案:

答案 0 :(得分:0)

您的onRendered功能需要修复:

Template.something.onRendered(function() {
    Template.instance().templateDictionary.set( 'showExtraFields', true );
});