我正在尝试使用 json2html 格式化数据
数据如下:
var data = [
{'name':'Bob','level':1},
{'name':'Frank','level':2},
{'name':'Bill','level':3},
{'name':'Robert','level':1},
{'name':'Chen','level':3},
{'name':'Will','level':2}
];
变换如下:
var transform = {"tag":"div","class":"player","children":[
{"tag":"div","class":"p-name","html":"${name}"},
{"tag":"div","style":"background:yellow","class":"p-level","html":"${level}"}
]}
但我需要根据级别对上面 div 的背景颜色进行着色,例如级别 1 - 黄色,级别 2 - 绿色,级别 3 - 红色。