Meteor: Where to store a selected object for a tempate -


i new meteor , have simple question can't seem find answer for...

i have simple page list of people down left, , template shows details on right editing, actions , such.

when click person on left, best place store selected person object template use? i've built 1 page stored in "selectedperson" session object, doesn't seem that's best place. advice on how store template , related js code without polluting session space?

meteor templates support ability arbitrarily define variables within scope of template.

you use events quite change current template data space reflect selected person.

quick , dirty below

<template name='personselector'>     <div class='personlist'>         <ul id='personslisting'>             {{#if personsready}}                 {{#each persons}}                     <li class='person' data-id='{{this._id}}'>{{this.name}}</li>                 {{/each}}             {{/if}}         </ul>     </div>      <div class='persondetails'>         {{#if getselectedperson this.selectedperson}}             {{#with getselectedperson this.selectedperson}}                 <div class='persondisplay'>                     <h1>person name: {{this.name}}</h1                     ...                     ...                     ...                 </div>         {{else}}             <p>please click on person list on left</p>         {{/if}}     </div> </template>  template.personselector.created = function() {     this.data.selectedperson = null; }  template.personselector.events({     'click .showperson': function(event, template) {         e.preventdefault();         // id of person selected , bind template         var _id = $(event.target).data('id');         if(_id) template.data.selectedperson = _id;      } }) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -