gpt4 book ai didi

javascript - 如何使用 Underscore js 模板将数组转换为 HTML 表格?

转载 作者:行者123 更新时间:2023-11-30 11:51:27 25 4
gpt4 key购买 nike

我有这个数组,

[
{"Product":"A","time":"00:21:59","date":"2016-09-05"},
{"Product":"B","time":"00:11:59","date":"2016-09-07"},
{"Product":"A","time":"00:11:59","date":"2016-09-08"}
]

我想把它变成这样,

Type | Mon   | Tue | Wed   | Thu   | Fri | Sat | Sun
--------------------------------------------------
A |0:21:59| | |0:11:59| | |
B | | |0:11:59| | | |

这是这个表示的数组,

[{"Type":A,"Mon":"0:21:59","Tue":"","Wed":"","Thu":"0:11:59","Fri":"","Sat":"","Sun":""},
{"Type":B,"Mon":"","Tue":"","Wed":"0:11:59","Thu":"","Fri":"","Sat":"","Sun":""}]

如何使用 Underscore 实现?我尝试使用 _.object 但我认为这不是解决方案。

最佳答案

您需要遍历数组。下划线模板使用普通的旧 JavaScript,通过 <% %> 嵌入标签。使用 _.eachArray#forEach遍历数组。

关于javascript - 如何使用 Underscore js 模板将数组转换为 HTML 表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39323529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com