如何从对象的嵌套数组中获取值?
这是我的API外观:
{
"id": 7,
"code": "ABC123",
"name": "Abu Bakar Enterprise",
"speCompanyDetails": [
{
"id": 1,
"speCompanyId": 7,
"registrationType": "2",
"registrationNo": "12345678",
"registrationYear": 2005,
"annualIncome": 100000,
}
]
}
我的目标是我想获取代码和名称的价值,但同时我也想从speCompanyDetails.annualIncome获取价值
当前我的查询类似于这样:
const SUPPLIER_INFO_QUERY = gql`
query SupplierInfoQuery($mainSuppId: String!) {
supplierInfo(id: $mainSuppId)
@rest(path: "services/supplier/api/spe-companies/{args.id}", method: "GET", type: "SupplierInfo") {
id
name
code
speCompanyDetails
}
}
`;
但是anuualIncome的值未定义。
答案 0 :(得分:-1)
const SUPPLIER_INFO_QUERY = gql
query SupplierInfoQuery($mainSuppId: String!) {
supplierInfo(id: $mainSuppId)
@rest(path: "services/supplier/api/spe-companies/{args.id}", method: "GET", type: "SupplierInfo") {
id
name
code
speCompanyDetails{ annualIncome }
}
}
;