javascript - Meteor, how to set context data in template event function -


i set context data in event handler inserts new uploaded photos image fscollection. want set newly generate id of photo file. need pass id child template further processing. below code working with:

how should define data want use later in event handler?

images.js  template.profile.events({         'change #uploadbtn': function(event, template) {             var name = $("#uploadbtn").val();             $("#uploadfile").val(name);             fs.utility.eachfile(event, function(file) {                 images.insert(file, function (err, fileobj) {                                    if (err){                         // handle error                     }                      else { //here want set fileobj._id data further usage.                      }                  });             });         }     });      template.imageview.helpers({         images: function () {                       return images.findone({_id: this.imageid});          }     });  template.imageview.events({             'click #deletebtn': function (event) {                 this.remove();             }         }); 

template file

  images.html      <template name="profile">       <input id="uploadfile" placeholder="choose file" disabled="disabled" style="cursor: auto; background-color: rgb(235, 235, 228); "/>       <div class="fileupload btn btn-primary">         <span>upload</span>         <input id="uploadbtn" type="file" name="…" class="upload">       </div>       {{> imageview}}     </template>      <template name="imageview">       <div class="imageview">          {{#if images}}           <div style="width: 120px;height: 120px;margin-bottom: 30px;">             <div style="float: middle;">               {{#with images}}               <button id="deletebtn" type="button" class="btn btn-primary" >delete</button>               {{/with}}             </div>              <a href="{{images.url}}" target="_blank" >               <img src="{{images.url}}" alt="" class="thumbnail" style="width: 96px; height: 96px;"/>             </a>                   </div>          {{/if}}       </div>     </template> 

you have couple choices.

  1. include _id of image in object referring it
  2. include _id of object in image parentid or similar

for first case, in callback image.insert use _id of image , .update() on parent object (is user perhaps?) include reference image. if you're allowing multiple images might want update array _ids.

in second case can update object inserted in callback insertion parentid need.

then need include appropriate clause in query dependent images , reactivity update automatically.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -