如何使用meteor.js填充bootstrap模式中的现有数据

时间:2015-11-24 11:53:18

标签: twitter-bootstrap meteor

addinfo.html

<template name="addInfo"> <div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">Add Art Description </h4> </div> <div class="modal-body"> <form class="add-image-info"> <div class="form-group"> <label>Title</label> <input type="text" class="form-control" id="name" name="title" placeholder="title" > {{title}} </div> <div class="form-group"> <label>Category</label> <input type="text" class="form-control" id="story" name="category" placeholder="category"> {{category}} </div>
<div class="form-group"> <label>Art Description</label> <textarea class="form-control" id="name" name="artdescription" placeholder="Description ...."> {{artDescription}} </textarea> </div> <button type="submit" class="btn btn-primary" id="save">Submit</button> <button type="button" class="btn btn-default" data- dismiss="modal">Close</button> </form> </div> </div> </div> </div> </template>

addinfo.js

`Template.addInfo.events({      'submit .add-image-info':function(event){

    event.preventDefault();
    var imageId = Session.get('imageId');
    var a_title = event.target.title.value;
    var a_category = event.target.category.value;
    var a_description = event.target.artdescription.value;

        Images.update({ _id: imageId }, { $set: { title: a_title, category: a_category, description: a_description } });

        toastr.success('Art information added ... ');

        Modal.hide('addInfo');

});`

如何使用模态中的现有值填充标题,类别,描述

打开模态时,应存在包含现有数据的默认值。

1 个答案:

答案 0 :(得分:0)

 Template.addInfo.helpers({
  Images:function(){
 return Images.find();
 }
 });

如果您有多个图像并且想要显示特定图像的数据,则必须找到一些参数。你还必须添加

   <template name="addInfo"> 
  {{#each Images}}
   <div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel">..Remaining Code...</div>
   {{/each}}
  </template>