javascript - Meteor: Rerun code when template variable changes -


i created template, audioplayer-element. id of audio-file passed element via template-variable. this:

{{>audioplayer audio=audio}} 

the containing template used subsequent pages audioplayer doesn't rerendered, content of pages change (like having page/1, page/2, page/3 on every page element on same place). want load correct file, matching id of variable passed. howler, , need subscription url of file related id.

template.audioplayer.created = function () {      var audioid = this.data.audio;     var subscription = this.subscribe('audio', audioid); //this variable      if (subscription.ready()) {         var audiourl = audio.findone(audioid).url;         var audio = new howl({             urls: [audiourl]         })     } } 

because created-function run once, want have run every time go new page, make sure have correct audio file matching right page.

i've tried wrapping piece in tracker.autorun doesn't seem solve problem. doesn't react on change of this.data.audio-variable. variable change, @ least when put variable in helper , display it.

any ideas?

right now, audioid isn't reactive. you'll need change session var, or (even better) query parameter in url. i'll assume know how this.

ok, have reactive variable, need rerun block of code every time variable changes. let's use autorun.

as have it, block of code subscription, returns 1 result & chances url isn't going change while listening tunes. that's sad, sorry subscription. better if had method grabbed url server.

tracker.autorun(function() {   var audioid = session.get('audioid');   meteor.call('getaudiourl', function(err,res) {     if (err) throw err;     var audio = new howl({       urls: [res]     })   }) });  //in server folder meteor.methods({   'getaudiourl': function(audioid) {     return audio.findone(audioid).url;   } }); 

boom. no useless subs & reactivity can shake stick at.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -