1.若后台传来的变量是列表套字典的格式,形如:
record = [
{utilCPU: 1.7645939086294395, recordTm: datetime.datetime(2015, 2, 12, 15, 34, 8, 950000)},
{utilCPU: 1.7831072874493914, recordTm: datetime.datetime(2015, 2, 12, 15, 59, 58, 900000)},
{utilCPU: 1.742658585858584, recordTm: datetime.datetime(2015, 2, 12, 16, 25, 48, 850000)}
]
则前端取值可以如下:
var index = 0;
var cpu = new Array(); var date = new Array(); //装填数据
{% for i in record %}
index++;
cpu[index] = "{{i.utilCPU}}";
date[index]="{{i.recordTm}}";
{% endfor %}
2.若数据为字典套字典,形如:
info_db = {
'192.168.1.108':
{'ethx': ['eth2', 'eth3'], 'dios': ['eth2', 'eth3']},
'192.168.1.86':
{'ethx': ['eth2', 'eth3'], 'dios': ['eth2', 'eth3']}
}
则前端取值可以如下:
{% for ip,name in info_db.items %}
var ip = "{{ip}}"; var disk = "{{name.dios}}"; var net = "{{name.ethx}}";
{% endfor %}