这是我的 ejs 代码<% var tag = [''] %><form action="/like" method="POST"> <% for (var i in tag){%> Tag: <input type="text" name="likes[]" value="<%= tag[i].likes %>"/><br><br> <button type="submit" value="accept">Send Tag</button><br><br><hr> <%} %></form>这是我的 controller.js 代码control.post('/like', (req, res, next) => { let tags = [req.body.likes]; console.log(tags); iglike(tags); next(); res.send(tags); });当我[]从name = "likes[]"代码中删除时,会完美地返回输入的数据。但是在控制台日志中name = "likes[]" 返回代码。undefined 例如:喜欢 []Input : App, WebOutput: [null] , In Console: Undefined没有喜欢[]Input: app, webOutput: ['app, web'] ( Stores them into single array)我希望我的输出是Input: app, example, thanksOutput: ['app','example','thanks']我正在使用 EJS 视图引擎和 node-express 我app.use(express.urlencoded({extended: false}))也在我的 app.js 中添加了代码。
1 回答
动漫人物
TA贡献1815条经验 获得超10个赞
更改扩展为真:
app.use(express.urlencoded({extended: true}))并从 req.body.likes 中删除方括号:
let tags = req.body.likes;
添加回答
举报
0/150
提交
取消
