這是我的 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 中添加了代碼。
EJS 中的數組在 NodeJS 中返回未定義和空值 - Express
莫回無
2022-12-18 16:12:36