ngFor之后将多个项目分组在一起

时间:2018-11-18 02:44:38

标签: angular

目前,我有一个ng模板,可以从数组中输出项目。我在尝试将key_idkey_name组合在一起时遇到麻烦

即( key_id = 1,key_name = hello1 ),( key_id = 2,key_name = hello2 )...现在,当我通过updateDate传递值时,输出应该为 hello1:1,hello2:2

<ng-template ngFor let-key [ngForOf]="item['data']['keys']">

    <a class="text-success" title="Edit Menu" 
    (click)="updateData(item['data']['title'],
    item['data']['url'],key['tag_id'],key['key_name'],false)">

        <i class="text-success fa fa-edit toogleIcon"></i>

    </a>

</ng-template>

JSON

"data": [
{
"data": {
"id": "1",
"title": "Location",
"url": "location",
"keys": [
{
"key_id": "1",
"key_name": "DefaultLine"
},
{
"key_id": "4",
"key_name": "Mainline"
}

TS for UpdateData

private updateData(title: any, url: any, key_id: any, key_name: any, flag: boolean) {
  console.log('title=>', title);
  console.log('url=>', url);
  console.log('key_name=>', key_name);
  console.log('key_id=>', key_id);
  this.title = title;
  url === null ? this.url = "" : this.url = url;
  key_id === null ? this.key_id = "" : this.key_id = key_id;
  key_name === null ? this.key_name = "" : this.key_name = key_name;
}

1 个答案:

答案 0 :(得分:2)

updateData元素的a函数调用中,第三个参数查找tag_id属性。根据我对JSON的了解,它应该在寻找key_id参数。也许就是这样吗?