With Meteor's iron-router, how do you re-render the template from a template event?

StackOverflow https://stackoverflow.com/questions/23586360

  •  19-07-2023
  •  | 
  •  

문제

My template shows different content based on a non-reactive value (in localStorage). I would like to do the following:

Template.foo.events
  'click #link': ->
    localStorage.setItem 'key', 'different'
    // re-render template foo

this.render() is undefined. Router.render('foo') does nothing.

도움이 되었습니까?

해결책

The easiest way is to use a dependency tied to your value.

keyDep = new Deps.Dependency()

Template.foo.events
  'click #link': ->
    localStorage.setItem 'key', 'different'
    keyDep.changed()

Template.foo.key = ->
  keyDep.depend()
  return localStorage.getItem 'key'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top