我的 JSON 数据有一些问题。我正在建立一个网站,用户应该能够在其中创建食谱。为此,他可以输入名称、成分和烹饪过程。在我的网站上,用户可以找到食谱并订阅它们。问题是,有多种成分,但在我的网站上,总是只有第一个项目......就像它没有阅读整个数组一样。
我的 JSON 看起来像这样:
"_id" : ObjectId("5c2ff33debbe541cdc500594"),
"subscriber" : [
{
"_id" : ObjectId("5c2ff340ebbe541cdc500595"),
"userID" : "5c2ff31bfa14ec17b8ad10c4",
"username" : "Dominik"
}
],
"titel" : "Spaghetti Bolognese",
"theme" : "Meat",
"ingredients" : "Noodles, Meat, Sauce",
"discription" : "Cook Noodles and meat. Cook the sauce."}
如您所见,系统正在正确保存信息。我打印所有这些的代码就是这样
<div id="content">
<% if(subscriptions.length>0) { %>
<% for(var i=0; i < subscriptions.length; i++) { %>
<% if("") { %>
<%} else {%>
<div id="recipe_titel"><%=subscriptions[i].titel%></div>
<div id="recipe_ingredients"><%=subscriptions[i].ingredients%></div>
<div id="recipe_discription"><%=subscriptions[i].discription%></div>
<td><button type="submit" class="button_unsubscribe" value="<%=subscriptions[i]._id%> <%=subscriptions[i].recipeID%>" id="button_small">Subscribe</button></td>
</tr>
<% } %>
<% } %>
<% } %>
在我的网站上,结果是
Spaghetti
Bolognese
Noodles,
我不知道为什么系统没有打印正确的结果......它被正确保存。