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):

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

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
Post a Comment