input name depended in the index in array in this way:
<div id="editAboutSantences<%=i%>" class="edit-container">
<div class="input-container">
<label> content: </label>
<input type="text" name="inputAboutSentences<%=i%>" id="inputAboutSentences<%=i%>" value="<%= digitalCard.about.sentences[i].content %>">
</div>
<% } %>
in the controller I try to get access to this input like this:
for (let i = 0; i < digitalCard.digitalCard.about.sentences.length; i++) {
const sentence = digitalCard.digitalCard.about.sentences[i];
sentence.content = req.body.inputAboutSentences+i;
console.log('inputAboutSentences0 = '+req.body.inputAboutSentences+i);
}
the input:
inputAboutSentences0 = undefined0
this is don't work because req.body.inputAboutSentences0 is object, I worked in this way in all the project and now i stuck. Ideas how to solve this ?
You can access inputAboutSentences*
property like:
sentence.content = req.body[`inputAboutSentences${i}`];
Using:
${expression}
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.