iT邦幫忙

0

Nodejs讀取嵌套數組的值顯示在Jade(Pug)

各位好,小弟最近在做一個項目需要讀取mongoDB中的數值顯示在網頁上。
但是當我處理這組嵌套數組時出現了一些問題總顯示Undefined

這是我的數據格式https://ithelp.ithome.com.tw/upload/images/20190318/20108632A90bewzrsf.png

Nodejs 找到這組數據後直接render到網頁:
return res.render("order/PoDetailPage", { results });

然後在網頁上(pug)進行讀取失敗, 顯示undefined
https://ithelp.ithome.com.tw/upload/images/20190318/20108632cgmLx1FlCE.png

請教各位大大如何讀取嵌套數組中的Price值($32.19 和 $51.9)

froce iT邦大師 1 級 ‧ 2019-03-18 20:31:04 檢舉
你results只有1筆,並不是array吧?
JS中for in的解說:
https://pjchender.blogspot.com/2016/06/javascript-for-in-function.html

簡單的說你如果拿object丟到for in迴圈,你的Po變數應該是object的prop值,也就是 "_id"、 "username"這些字串值。
2deedee2 iT邦新手 5 級 ‧ 2019-03-18 21:23:44 檢舉
好的,明白,解決了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答