如何从流星动态生成的表单中获取文本框的值,而文本框的数量不固定
How to get values of textbox from dynamically generated form in meteor, while the number of textbox is not fixed
我想从动态生成的表单中获取文本框的值并存储在数据库中。文本框的数量不固定。表单在模板中
<template name="product">
<input type="text" id="txt1">
<input type="text" id="txt2">
.......
.......
<button id="CreateNewProduct">Create new product</button>
</template>
我想在"product"集合中插入文本框值。我在这里展示了两个文本框供参考。可能是3 4 5 ......最多n个。也可以包含复选框和单选。
你能建议我如何进行这项任务吗?
您需要遍历现有的输入元素,并将它们对应的id
s与它们在表单中作为Product集合特定属性的引用的n
th进行匹配。
Template.product.events({
"submit form": function(event, template) {
var product = {};
template.$("input").each(function(index) {
product["property"+index] = template.$("input#txt"+index).val();
});
Product.insert(product);
}
})
相关文章:
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- 如何获取经过编辑的文本
- 使用 jQuery 从下拉列表中获取所选文本
- 如何获取文本框组的值,并使用jquery将它们放入(key:Value)数组中
- 使用格式化文本获取 DIV 或跨度的动态宽度高度
- 通过搜索 td 文本获取嵌套表 ID
- 将 HTML 元素的文本获取到数组中
- 如何从响应文本获取 JSON 字符串到 JavaScript 中
- 如何根据选项文本获取选项索引
- 通过其文本获取dom节点
- 如何通过锚文本获取对象
- 在Javascript/JQuery中从超链接文本获取Href
- 如何将函数中的文本获取到此通知警报中
- 根据指定的文本获取标记
- 通过匹配文本获取json数据到数组中
- 如何通过id和输出文本获取选项元素
- 通过相邻的TH内部文本获取TD中的文本
- 如何将任何指定网页中的文本获取到变量中
- 通过内部文本获取所有元素
- 从给定的HTML文本获取JQuery