Javascript
1//ejs 2 <% for(var i=0;i<categories[0].length;i++) {%> 3 <% if(categories[1][i].id == i){%> 4 <h2><%=categories[0][i].title%> 5 <p><%=categories[1][i]sub_title%> 6 <%}%> 7 <%}%> 8
//console.log(categories) [ [ { _id: 5a14fe9fc788204f8a6afddc, id: 1, title: 'A' }, { _id: 5a14fea8c788204f8a6afddd, id: 2, title: 'B' }, { _id: 5a14feb8c788204f8a6afdde, id: 3, title: 'C' }, { _id: 5a14febec788204f8a6afddf, id: 4, title: 'D' }, { _id: 5a14fec5c788204f8a6afde0, id: 5, title: 'E' }, { _id: 5a14feccc788204f8a6afde1, id: 6, title: 'F' } ], [ { _id: 5a150379eea02617efffa696, id: 1, sub_title: 'momo' }, { _id: 5a15039ceea02617efffa697, id: 1, sub_title: 'hana' } ] ]
Node.js(Express)+MongoDBで勉強をしているのですが、
モジュールのejsで多次元配列をfor(categories[0])の中でif(categories[1])を行い、
データを表示させたいのですが、categories[1][i].idのidがUndifineエラーが発生します。
categories[0][i].titleは問題なく表示されます。
そこでfor文のcategories[0]をcategories[1]にしたところ、今度はtitleがUndefineになりました。
ejsでは2次元配列は処理できないのでしょうか?
わかりずらい文章で申し訳ございません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/23 08:38
2017/11/23 08:44
退会済みユーザー
2017/11/23 08:51