我試圖創建一個應用程序,它在輸入字段中輸入後保存信息!我在添加具有多個輸入字段的表單時遇到了一些問題。如何在Meteor.js中添加所有表單的元素?
這是我的HTML和JS文件:
import { Template } from 'meteor/templating';
import { Tasks } from '../api/tasks.js';
import './body.html';
Template.body.helpers({
tasks() {
// Show newest tasks at the top
return Tasks.find({}, { sort: { createdAt: -1 } });
},
});
Template.body.events({
'submit .new-task'(event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
const target = event.target;
const text = target.text.value;
// Insert a task into the collection
Tasks.insert({
text,
createdAt: new Date(), // current time
});
},
});
<body>
<div class="container">
<header>
<form class="new-task">
<input type="text" name="text" placeholder="Type to add new tasks" />
</form>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
請告訴我,我怎麼可能增加超過2個輸入,並通過點擊提交按鈕顯示呢?
很難理解什麼是你的問題。但是,您是否嘗試重複使用替換name =「text」並替換屬性名稱並相應修改數據引用? – AirBorne04