admin管理员组文章数量:1410697
I'm trying to loop through a list of dicitionaries returned from my python Flask api and insert the information into a row in a table where the first column is the Event "type" and the second column is "Event Time". The list of dicitonaries looks like this:
{ "type": "Creation Event", "time": event_results[0] },
{ "type": "Deletion Event", "time": event_results[1] },
{ "type": "Last Update Event", "time": event_results[2] }
Here is my current way of filling in the table
return this.getData().then(event => {
this.clear()
this.addRow(['Event Type', 'Event Time'], 'th')
if (!event) return;
Object.keys(event).forEach(dict in list => {
this.addRow([this.dict[type], dict[time]])
})
})
}
Any advice on this is greatly appreciated.
I'm trying to loop through a list of dicitionaries returned from my python Flask api and insert the information into a row in a table where the first column is the Event "type" and the second column is "Event Time". The list of dicitonaries looks like this:
{ "type": "Creation Event", "time": event_results[0] },
{ "type": "Deletion Event", "time": event_results[1] },
{ "type": "Last Update Event", "time": event_results[2] }
Here is my current way of filling in the table
return this.getData().then(event => {
this.clear()
this.addRow(['Event Type', 'Event Time'], 'th')
if (!event) return;
Object.keys(event).forEach(dict in list => {
this.addRow([this.dict[type], dict[time]])
})
})
}
Any advice on this is greatly appreciated.
Share Improve this question edited Aug 21, 2019 at 13:37 Andrej Kesely 196k15 gold badges58 silver badges103 bronze badges asked Aug 21, 2019 at 13:35 mangokittymangokitty 2,4393 gold badges15 silver badges20 bronze badges 1-
is
event
the array of objects ? – Taki Commented Aug 21, 2019 at 13:40
1 Answer
Reset to default 5You can loop through the array of objects directly using forEach
:
event.forEach(dict => this.addRow([obj.type, obj.time]));
your code :
return this.getData().then(event => {
this.clear();
this.addRow(["Event Type", "Event Time"], "th");
if (!event) return;
event.forEach(({type, time}) => this.addRow([type, time]));
});
本文标签: loop through list of dictionaries in JavascriptStack Overflow
版权声明:本文标题:loop through list of dictionaries in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745042083a2639137.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论