我在python里面定义了一个list,list里面是多个字典组成。现在js中获取的值是[{'date': '2017-09-04', 'seeNumber': [10], 'time': ['10']}, {'date': '2017-09-06', 'seeNumber': [10, 0], 'time': ['06', '08']}, {'date': '2017-09-07', 'seeNumber': [1, 0], 'time': ['06', '08']}, ] 现在前端页面有个下拉选框,我想选中2017-09-04时候,取出其对应的seeNumber与time的value值怎么做
1 回答
aluckdog
TA贡献1847条经验 获得超7个赞
data_list = [{'date': '2017-09-04', 'seeNumber': [10], 'time': ['10']}, {'date': '2017-09-06', 'seeNumber': [10, 0], 'time': ['06', '08']}, {'date': '2017-09-07', 'seeNumber': [1, 0], 'time': ['06', '08']}, ]
val = None
for item in data_list:
if item.get('date', '') == '2017-09-04':
val = (item.get('seeNumber', 'NA'), item.get('time', 'NA'))
break
else:
val = ('Date Not Found', 'Date Not Found')
print val
添加回答
举报
0/150
提交
取消