各位大神好:
弱弱的我买了欧莱礼的书想学习 Node.js 和 express 搭配的原理和语法,因为 handlebars 坏掉只好改用 Jade 模板,今天从 Node.js 传递物件到 Jade 时吃了不少苦头,现在已解决把成果分享给大家。以下是物件
const weatherData = [ { location: { name: 'Portland',}, temp: '59 F', }, { location: { name: 'Bend',}, temp: '51 F', },]
一般 Jade 接受 Node.js render 过来的变数都是用 #{XXX},但我一直印出 [object, Object], google 很久终于找到解方,以下是 Jade 的 code
each weather in weathers each value, key in weather if (key == 'location') each value_1, key_1 in value span= key_1 + ': ' + value_1 + ' ' else span= key + ': ' + value + ' '
希望这点微末功夫有帮到大家,献丑了!