【发布时间】:2018-12-03 20:46:08
【问题描述】:
所以我试图按某个属性对一组对象进行分类。第一次使用 groupBy 效果很好。现在我需要遍历这些分组并根据单独的属性再次对它们进行分组。我遇到了这个问题,有人可以帮我吗?
TS
this.accountService.getAccountListWithBalance().subscribe(accounts => {
this.accountList = _.groupBy(accounts, 'category');
for (var property in this.accountList) {
if (this.accountList.hasOwnProperty(property)) {
this.accountList.property = _.groupBy(this.accountList.property, 'subcategory');
}
}
generateArray(obj){
return Object.keys(obj).map((key)=>{ return {key:key, value:obj[key]}});
}
HTML:
<ul *ngFor="let item of generateArray(accountList)">
<strong>{{ item.key }}</strong>
<li *ngFor="let i of item.value">{{i.name}}</li>
</ul>
没有为下一级交互设置 HTML,但我知道如果我只是控制台记录结果对象,它就不起作用。就像我说的那样,它是第一次被排序,而不是第二次。
【问题讨论】:
-
如果能分享账户服务api返回的json响应会很有帮助
-
您的帐户模型的数据结构是什么?
标签: javascript angular lodash