Accessing template helper dictionary in Meteor event handler

拟墨画扇 提交于 2019-12-04 07:37:37

Helpers are just functions and thus can be passed around and assigned to other variables at will, so you could define a function and then assign it the helper2 key of the template helpers and call by it's original reference from the event handler.

var helperFunction = function() {
    return Collection2.find({_id: this.object2_id});
};

Template.myTemplate.helpers({
    helper1: function() {
        var object1 = this;  // data context set in iron:router...path is context dependent
        // modify some values in object1
        return this;
    },
    helper2: helperFunction
});

Template.myTemplate.events({
    'submit form': function(event) {
        event.preventDefault();
        var cursor = helperFunction();
    }
});

If you can modify helpers from events, then, any part of the Meteor application can do, which is against the design philosophy of Blaze!

Blaze is designed to be uni-directional data binding tempting system. What you ask for can be achieved using Angular (used on its own, or side by side with Blaze, look at THIS), which is by nature a 2-way data binding tempting system.

You may also want to check React, which is also a 2 way data binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!