从哈巴狗中的 JSON object 正确创建 table
Creating a table properly from a JSON object in pug
我正在尝试将我的 JSON object 分解成单独的元素并动态填充 table。)
我猜我试着用哈巴狗做一种地图(动态填充 table。
tr
td.resultLog
- let heatResult1Log = result.heat1Logs;
for heatItem in heatResult1Log
for item of heatItem
#{item}
tr
这是将结果发送给哈巴狗的代码:
return {
"Failures": {
"coolCount1":coolFail1Rows.length/2 , coolCheck1Index:coolFails1Array,cool1Logs:coolFails1Logs,
"heatCount1":heatFail1Rows.length/2 , heat1Logs:heatFails1Logs
}};
}
这是我的 JS 代码返回的 object(暂时忽略加热端,因为答案是一样的)
{ Failures:
{ coolCount1: 2,
coolCheck1Index: [ 8865, 8866, 9077, 9078 ],
cool1Logs:
[ '[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]',
'[8866,"2019-03-14T04:00:00.000Z","3:15:00",null,null,null,null,null,null,null,"end"]',
'[9077,"2019-03-14T04:00:00.000Z","20:50:00","cool","compressorCoolOff","auto","Home",76.8,76.8,77.3,"end"]',
'[9078,"2019-03-14T04:00:00.000Z","20:55:00",null,null,null,null,null,null,null,"end"]' ],
} }
我尝试映射到个人 objects(因为我希望它看起来像一个正常的 table)
table.resultHeader
tr
th Index
th Date
th Time
th System Setting
th System Mode
th Calendar Event
th Program Mode
th Cool Set Temperature
th Heat Set Temperature
tr
tr
td.resultLog
- let heatResult1Log = result.heat1Logs;
for heatArray in heatResult1Log
for item in heatArray
td #{item}
tr
其中returns这个数组一个字母一个字母貌似。
现在技术上我明白了,因为结果是作为数组的数组发送的,但是有什么选择吗?我希望我的 table 和索引对齐,它 returns 作为数组的数组而不是单个元素的数组。
我的预期结果是它看起来像正常的 table 即
<table style="width:100%">
<tr>
<th>Index</th>
<th>Date</th>
<th>Time</th>
(etc)
</tr>
<tr>
<td>0</td>
<td>Sept 2</td>
<td>5:30</td>
</tr>
</table>
在每个 "inside array" 的末尾(因为它是一个带有数组的数组),它将开始一个新行并为下一个数组填充元素。这就是现在的样子……(索引应该只有每个数组的第一个元素,日期是第二个,依此类推)
我已经添加了一个示例 - 数字 5067 应该出现在索引下(作为返回的索引),日期应该出现在日期下。
如果我在一个循环中放置一个循环,会发生这种情况:
解决方案可能如下所示:
cool1Logs:
[ '[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]',
'[8866,"2019-03-14T04:00:00.000Z","3:15:00",null,null,null,null,null,null,null,"end"]',
'[9077,"2019-03-14T04:00:00.000Z","20:50:00","cool","compressorCoolOff","auto","Home",76.8,76.8,77.3,"end"]',
'[9078,"2019-03-14T04:00:00.000Z","20:55:00",null,null,null,null,null,null,null,"end"]' ],
您正在迭代的对象是字符串数组。
'[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]',
此代码运行正常,它会为您提供字符串中的字符。
for item in heatArray
td #{item}
您需要将其作为数组传递给哈巴狗模板。如下图
[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]
我正在尝试将我的 JSON object 分解成单独的元素并动态填充 table。)
我猜我试着用哈巴狗做一种地图(动态填充 table。
tr
td.resultLog
- let heatResult1Log = result.heat1Logs;
for heatItem in heatResult1Log
for item of heatItem
#{item}
tr
这是将结果发送给哈巴狗的代码:
return {
"Failures": {
"coolCount1":coolFail1Rows.length/2 , coolCheck1Index:coolFails1Array,cool1Logs:coolFails1Logs,
"heatCount1":heatFail1Rows.length/2 , heat1Logs:heatFails1Logs
}};
}
这是我的 JS 代码返回的 object(暂时忽略加热端,因为答案是一样的)
{ Failures:
{ coolCount1: 2,
coolCheck1Index: [ 8865, 8866, 9077, 9078 ],
cool1Logs:
[ '[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]',
'[8866,"2019-03-14T04:00:00.000Z","3:15:00",null,null,null,null,null,null,null,"end"]',
'[9077,"2019-03-14T04:00:00.000Z","20:50:00","cool","compressorCoolOff","auto","Home",76.8,76.8,77.3,"end"]',
'[9078,"2019-03-14T04:00:00.000Z","20:55:00",null,null,null,null,null,null,null,"end"]' ],
} }
我尝试映射到个人 objects(因为我希望它看起来像一个正常的 table)
table.resultHeader
tr
th Index
th Date
th Time
th System Setting
th System Mode
th Calendar Event
th Program Mode
th Cool Set Temperature
th Heat Set Temperature
tr
tr
td.resultLog
- let heatResult1Log = result.heat1Logs;
for heatArray in heatResult1Log
for item in heatArray
td #{item}
tr
其中returns这个数组一个字母一个字母貌似。
现在技术上我明白了,因为结果是作为数组的数组发送的,但是有什么选择吗?我希望我的 table 和索引对齐,它 returns 作为数组的数组而不是单个元素的数组。
我的预期结果是它看起来像正常的 table 即
<table style="width:100%">
<tr>
<th>Index</th>
<th>Date</th>
<th>Time</th>
(etc)
</tr>
<tr>
<td>0</td>
<td>Sept 2</td>
<td>5:30</td>
</tr>
</table>
在每个 "inside array" 的末尾(因为它是一个带有数组的数组),它将开始一个新行并为下一个数组填充元素。这就是现在的样子……(索引应该只有每个数组的第一个元素,日期是第二个,依此类推)
我已经添加了一个示例 - 数字 5067 应该出现在索引下(作为返回的索引),日期应该出现在日期下。
如果我在一个循环中放置一个循环,会发生这种情况:
解决方案可能如下所示:
cool1Logs:
[ '[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]',
'[8866,"2019-03-14T04:00:00.000Z","3:15:00",null,null,null,null,null,null,null,"end"]',
'[9077,"2019-03-14T04:00:00.000Z","20:50:00","cool","compressorCoolOff","auto","Home",76.8,76.8,77.3,"end"]',
'[9078,"2019-03-14T04:00:00.000Z","20:55:00",null,null,null,null,null,null,null,"end"]' ],
您正在迭代的对象是字符串数组。
'[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]',
此代码运行正常,它会为您提供字符串中的字符。
for item in heatArray
td #{item}
您需要将其作为数组传递给哈巴狗模板。如下图
[8865,"2019-03-14T04:00:00.000Z","3:10:00","cool","compressorCoolStage1On","auto","Sleep",74,74,75.3,"end"]