从 Node.js 传递物件到 Jade 的微末功夫

各位大神好:
弱弱的我买了欧莱礼的书想学习 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 + ' '

希望这点微末功夫有帮到大家,献丑了!


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章