node.js - 如何使用复选框输入从 false 更改为 true?
问题描述
如果有人可以帮助我。我想做下一件事。使用复选框我想选择要放在索引页面上的帖子
这是我的架构
var foodSchema = new mongoose.Schema({
title:String,
image:String,
text:String,
video:String,
checkBox:{type:Boolean, default:false},
created:{type: Date, default:Date.now},
comments:[{
type: mongoose.Schema.Types.ObjectId,
ref:"comment"
}
]
});
这是我的 new.ejs 文件
<spam class="hederSpam">
<input type="checkbox" name="checked" value="true">
post
</spam>
```
here i wanna to display
``` <%newFood.forEach(function(check){ %>
<%if(check.checkBox===true){%>
<h3 class="indexh2"><%= check.title %></h3>
<%= check.checkBox%>
<a href="/food/<%= check._id%> " >Read More</a>
<% })%>
在 site.js 文件中我试图这样做但每次都给我错误..
food.create(req.body.foodForm, function(err, postFood){
var n = req.body.checked;
if(err){
console.log("err")
}else{
if( n == "true"){
food.checkBox=true;
}
res.redirect("/food");
}
})
});
解决方案
这似乎是一段奇怪的代码:
console.log("err)
我在这里放置下划线的地方也应该有空格:
name="checked"_value="true"
推荐阅读
- angular - 角度 10 - 在其他组件中加载组件
- string - 当我尝试在输出中添加字符串时,出现语法错误
- angular - 目标入口点中的错误缺少依赖项:对于子组件
- dart - 为什么即使在打印字符时控制台也是空的?
- java - 原生C调用后Android Bitmap保持不变
- android - React native - 在 Android 上启动应用程序的问题
- postgresql - Postgres表锁定删除查询
- vim - 如何选择弹出菜单中的第一项并在单个键绑定中关闭菜单以在 nvim 中自动完成?
- node.js - 如何将用户从 Strapi 迁移到 Firebase?
- android - 使用 detox 以不同方向查看 UI (Android)