0

我对PrimeNG 表非常陌生,我尝试将嵌套的 json 文档加载到表中,但我无法访问嵌套数组的数据。

我能够在 p-table 中加载 flatten json但在嵌套 json unbale 中加载嵌套数据

EX:{ field: "address", header: "Address ", title: "Person Address" } 对于此代码,我在地址列中获取[object, object]

我也尝试过像字段一样索引address[0].id但没有得到

这个从 API 获取的 json 样本数据

Retailers=[
        {
            "id":1,
            "name":"Preeti Mobiles",
            "address":[{
                "id": 1,
                "addressLine1":"31/A, 2nd cross, 1st floor",
                "addressLine2":"Tirumala Towers, Mejestic",
                "city":"Bengaluru",
                "state":"Karnataka",
                "country":"India",
                "pincode":500006
            },
            {
                "id": 2,
                "addressLine1":"31/A, 2nd floor",
                "addressLine2":"Hebbal",
                "city":"Bengaluru",
                "state":"Karnataka",
                "country":"India",
                "pincode":500091
            }
            ]
        },
        {
            "id": 2,
            "name": "Nanda Electronics",
            "address": [{
                "id": 1,
                "addressLine1": "78/A, 4nd cross, 1st floor",
                "addressLine2": "Kishan Empower, RR Nagar",
                "city": "Bengaluru",
                "state": "Karnataka",
                "country": "India",
                "pincode": 520006
            }
            ]

        },
        {
            "id": 3,
            "name": "Kishan Electronics",
            "address": [{
                "id": 1,
                "addressLine1": "86/A, 1nd cross, 2st floor",
                "addressLine2": "Nanda Building, Hebbala",
                "city": "Bengaluru",
                "state": "Karnataka",
                "country": "India",
                "pincode": 520036
            }
            ]
        }
    ]

输入脚本代码

ngOnInit() {
        this.person();
      }
     person(){
        this.personService.getpersonList().subscribe(data=>{
          this.person_details = data;
          console.log(this.person_details);
        });

        this.retailer_list = [
          { field: "name", header: "Name", title: "person Name" },
          { field: "address", header: "Address ", title: "person Address" }
          ];
      }
    }
4

0 回答 0