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

时间:2016-09-05 03:27:03

标签: javascript arrays underscore.js

我有这个数组,

[
  {"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,但我认为这不是解决方案。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您可以使用/** * Start SpringBoot server */ @SpringBootApplication(scanBasePackages= {"com.your.conf.package"}) //@ComponentScan(basePackages = "com.your.conf.package") public class Application { public static void main(String[] args) throws Exception { System.setProperty("server.port","8132")); System.setProperty("server.tomcat.max-threads","200"); System.setProperty("server.connection-timeout","60000"); ApplicationContext ctx = SpringApplication.run(Application.class, args); } } 循环和可选的forEach()参数为每个产品创建对象,然后使用Date#getDay()

为时间添加时间

&#13;
&#13;
thisArg
&#13;
&#13;
&#13;