标签云

微信群

扫码加入我们

WeChat QR Code

I'm new to meteor and I'm trying to get a hang of the whole reactivity thing. There isn't a specifc reason why I want this function to re-run, in fact, it not re-running is actually the desired behavior for my use case. I just want to know why this is happening so I can better understand the concepts. If I add a function as a property on a template instance, like this:Template.services.onCreated( function() {this.templates = ["web_design","painting","gardening"];this.current_index = new ReactiveVar(0);this.determineSlideDirection = function() {console.log(this.current_index.get());};});And then I update the reactive var in response to some event.Template.services.events({'click .nav-slider .slider-item': function(event, template) {var new_selection = event.currentTarget;template.current_index.set($(new_selection).index());}});The function is not re-run upon the invocation of the set() call. However, If I have a helper that utilizes the variable, it will be re-run. Template.services.helpers({currentTemplate: function() {var self = Template.instance();return self.templates[self.current_index.get()];}});Why is this?


Tracker.autorun is also commonly mistyped as Tracker.autofun because it gives you automatic FUN!

2019年04月19日24分27秒