如何使用jQuery我目前使用流星/火焰框架建立一个表来获取动态表

问题描述:

的输入字段值。表中的行将根据选定的供应商而改变。我已将class={{_id}}添加到该字段中,并将q.{{_id}},lot.{{_id}}exp.{{_id}}添加到数量,批次和过期日期INPUT如何使用jQuery我目前使用<strong>流星/火焰框架</strong>建立一个表来获取动态表

我想写一个提交事件来获得这些值,并将它传递给Mongo数据库。请建议一个很好的方法来循环这些行以获取值。

网站形象

enter image description here

部分代码的

receiveForm模板

<template name="receiveForm"> 
... 
<select data-placeholder="Select an option" class="sel2js form-control select select-primary" id="supplier_sel" name="supplier"> 
     {{#each suppliers}} 
     {{> sel_supplier}} 
     {{/each}} 
    </select> 
    </div> 
    <!-- Receive Lot Table --> 
    <table class="table table-bordered table-hover"> 
    <thead> 
     <tr> 
     <th>Product Name</th> 
     <th>Current Quantity</th> 
     <th>Unit of Measurement</th> 
     <th>Receive Quantity</th> 
     <th>Lot No</th> 
     <th>Exp Date (DD/MM/YYYY)</th> 
     </tr> 
    </thead> 
    <tbody> 
     {{#each items}} 
     {{> receiveRow2}} 
     {{/each}} 
    </tbody> 
</table> 
<div class="text-center"> 
    <button type="submit" class="btn btn-embossed btn-primary btn-wide" id="submitNewReceive" value="Submit">Submit</button> 
    <button type="reset" class="btn btn-embossed btn-warning btn-wide" value="Reset">Reset</button> 
</div> 
</form> 

receiveRow2模板

<template name="receiveRow2"> 
    <tr id="{{_id}}"> 
    <td class="pn">{{name}}</td> 
    <td class="pq">{{totalQuantity}}</td> 
    <td>{{uomid.name}} ({{uomid.unit}} {{uomid.unitname}}/{{uomid.name}})</td> 
    <td><input type="text" class="form-control" name="q.{{_id}}" placeholder="Quantity" /></td> 
    <td><input type="text" class="form-control" name="lot.{{_id}}" placeholder="Lot No XX/YYYY" /></td> 
    <td> 
     <div class="input-group datetimepicker text-primary"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> 
     <input class="set-due-date form-control" name="exp.{{_id}}" type="text" placeholder="วัน/เดือน/ปี"/> 
     <hr /> 
     </div> 
    </td> 
    </tr> 
</template> 

JS

Template.receiveForm.events({ 
    'submit form': function(event, template){ 
    var supplierSelected = Template.instance().supplierSelected; 
    items = Products.find({suppliers: supplierSelected.get()}); 
    event.preventDefault(); 
    docdate = event.target.docdate.value; 
    supplier = event.target.supplier_sel.value; 
    console.log("---event---"); 
    console.log(docdate) 
    console.log(supplier) 
    items.forEach(function(item){ 
     ???? 
    }) 
    } 
}) 

在第4行其缺少一个变种的项目, 以及在6号线,7 之后,我觉得你可以对他们的循环之前。(但是,他们将来自DB) ,但如果你想要得到的输入值,为什么你会要求在MongoDB的数据? 此外,我会preffer获取DB值作为承诺。

var items = Promise.resolve(Products.find({suppliers: supplierSelected.get()}); 

,并取回这样的项目:

items.then(function(item){console.log(item)}) 
+0

我试图从DB的ID,所以我可以尝试找到一种方式来获得输入名称= q.ID, lot.ID值。 – CHiEZ

+0

而你想用数据库存储的值填充值? – 2017-09-13 09:16:11

+0

现在我试图找到一种方式让输入字段值,这样我就可以在数据库填充它。 – CHiEZ