[英]How to show the selected option in a dropdown menu, with the mongoDB?
how to get data from the select option dropdown menu in mongodb如何从mongodb的选择选项下拉菜单中获取数据
I face this error --> ReferenceError: Selection is not defined我面临这个错误 --> ReferenceError: Selection is not defined
here I attached all the code and files how to solve this error ??在这里我附上了所有的代码和文件如何解决这个错误? what changes I need in my code
我的代码需要哪些更改
customer.model.js file customer.model.js 文件
const mongoose = require('mongoose');
var employeeSchema = new mongoose.Schema({
discount: {
type: Number
},
finalTotal: {
type: Number
},
selectt: {
type: Selection
}
});
mongoose.model('Employee', employeeSchema);
.html file .html 文件
<h3><a class="btn btn-secondary" href="/customer"><i class="fa fa-plus"></i> Create New</a> Employee List</h3>
<table class="table table-striped">
<thead>
<tr>
<th>discount</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each list}}
<tr>
<td>{{this.discount}}</td>
<td>{{this.selectt}}</td>
<td>{{this.finalTotal}}</td>
</tr>
{{/each}}
</tbody>
</table>
<form action="/customer" method="POST">
<input type="hidden" name="_id" value="{{employee._id}}">
<label for="selectt">Select Customer</label>
<select name="selectt" id="selectt" type="Selection" value="{{employee.selectt}}" required>
<option value="" disabled selected>Select Customer</option>
<option value="1">Mark Benson</option>
<option value="2">Bob Smith</option>
<option value="3">John Draper</option>
</select>
CustomerContoller.js file CustomerContoller.js 文件
function insertRecord(req,res){
var employee = new Employee();
employee.discount = req.body.discount;
employee.finalTotal = req.body.finalTotal;
employee.selectt= req.body.selectt;
employee.save((err, doc) => {
if(!err)
res.redirect('customer/list');
else{
console.log('error during record insertion : ' +err);
}
});
}
When defining mongoose Schema you need to define the data type with a particular field.定义 mongoose Schema 时,您需要使用特定字段定义数据类型。 In your code
type: Selection
is not a valid data type.在您的代码
type: Selection
不是有效的数据类型。 So identify the data type for the corresponding field and put it there.因此,确定相应字段的数据类型并将其放在那里。 For Example,
例如,
const mongoose = require('mongoose');
var employeeSchema = new mongoose.Schema({
discount: {
type: Number
},
finalTotal: {
type: Number
},
selectt: {
type: String
}
});
mongoose.model('Employee', employeeSchema);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.