Meteor: Preselected options lost after rerendering multiple select -


i have multiple select handlebar template in meteor.js. on first rendering, fine ("politics" , "people" preselected expected):

multiple select on first render

as template has rerendered (because session variable changes, e.g. session.set("foo", "hello world!")), third option not preselected anymore:

multiple select after dynamic changes

my setup:

<template name="select">   <select name="foo" multiple>     <option value="1">tech</option>     <option value="2" selected>politics</option>     <option value="3" selected>people</option>   </select> </template>  <template name="test">   {{foo}}   {{> select}} </template>  {{> test}} 
template.test.helpers(   foo: ->     session.get("foo") ) 

do have idea why options preselected anymore after rerendering?

solution is:

<template name="test">   {{#isolate}}     {{foo}}   {{/isolate}}         {{> select}} </template> 

typically, exact extent of re-rendering not crucial, if want more control, such performance reasons, can use {{#isolate}}...{{/isolate}} helper. data dependencies established inside #isolate block localized block , not in cause parent template re-rendered. block helper conveys reactivity benefits pulling content out new sub-template.

if put {{foo}} inside {{#isolate}} ... {{/isolate}} parent template won't rerendered, {{> select}} won't affected.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -