简体   繁体   English

如何使用jQuery获取动态表的输入字段值

[英]How to use jQuery to get Input Field Value of dynamic table

I'm currently using Meteor/Blaze framework to build a table.我目前正在使用Meteor/Blaze 框架来构建一个表。 The row in the table will change according to the selected supplier.表中的行将根据选定的供应商而变化。 I have added class={{_id}} to the field and q.{{_id}} , lot.{{_id}} , and exp.{{_id}} to the quantity, lot , and expire date INPUT .我已将class={{_id}}到字段和q.{{_id}}lot.{{_id}}exp.{{_id}}到数量、 lot 和到期日期INPUT

I'm trying to write a Submit Events to get these value and pass it to the Mongo Database.我正在尝试编写一个提交事件来获取这些值并将其传递给Mongo数据库。 Please suggest a good way to loop through these rows to get the value.请提出一种循环遍历这些行以获取值的好方法。

Website Image网站图片

在此处输入图片说明

Part of the code部分代码

receiveForm template接收表单模板

<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接收行 2 模板

<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 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){
      ????
    })
  }
})

In line 4 its missing a var before items, and also in line 6, 7.在第 4 行中,它在项目之前缺少一个 var,在第 6、7 行中也是如此。

After that I think you can loop on them.(But they will come from the DB).在那之后,我认为你可以循环使用它们。(但它们将来自数据库)。

BUT if you want to get the input values, why would you ask for a data in MongoDB?但是如果你想获得输入值,你为什么要在 MongoDB 中要求数据? Also I would prefer to get DB values as a promise.此外,我更愿意将 DB 值作为承诺。

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

and get back the items in this way:并以这种方式取回项目:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM