目前,我有一个ng模板,可以从数组中输出项目。我在尝试将key_id
和key_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;
}
答案 0 :(得分:2)
在updateData
元素的a
函数调用中,第三个参数查找tag_id
属性。根据我对JSON的了解,它应该在寻找key_id
参数。也许就是这样吗?