簡體   English   中英

在 React Js 中從數組列表中獲取輸入字段

[英]Getting input fields from Array List in React Js

我從 API 中提取數組,其中提到了輸入字段,下面是示例:

customerAttribute: Array(11)
0: {attributeId: 1, attributeName: "FirstName", attributeType: "String", isMandatory: false}
1: {attributeId: 2, attributeName: "LastName", attributeType: "String", isMandatory: false}
2: {attributeId: 3, attributeName: "DateOfBirth", attributeType: "Date", isMandatory: false}
3: {attributeId: 4, attributeName: "Email Address", attributeType: "String", isMandatory: false}
4: {attributeId: 5, attributeName: "Mobile Number", attributeType: "Number", isMandatory: false}
5: {attributeId: 6, attributeName: "Address Line 1", attributeType: "String", isMandatory: false}
6: {attributeId: 7, attributeName: "Address Line 2", attributeType: "String", isMandatory: false}
7: {attributeId: 8, attributeName: "City", attributeType: "String", isMandatory: false}

現在我已經 const an 其中提到了默認字段:

 const ABC = [
    { ...firstName, order: 1 },
    { ...lastName, order: 2 },
    { ...mobileNumber, order: 3 },
    { ...email, order: 4 },
    { ...address1, order: 5 },
    { ...address2, order: 6 },
    { ...city, order: 7 },
 ]

我只想顯示 CustomerAttribute 數組列表中可用的字段

任何人都可以建議我能做什么..?

首先,響應總是在 JSON 中,它將在數組中,它必須像下面是 for 循環,它將為您提供所需的值,例如 attributeID、attributeName

var  customerAttribute =
[ {attributeId: 1, attributeName: "FirstName", attributeType: "String", isMandatory: false},
 {attributeId: 2, attributeName: "LastName", attributeType: "String", isMandatory: false},
 {attributeId: 3, attributeName: "DateOfBirth", attributeType: "Date", isMandatory: false},
 {attributeId: 4, attributeName: "Email Address", attributeType: "String", isMandatory: false},
 {attributeId: 5, attributeName: "Mobile Number", attributeType: "Number", isMandatory: false},
 {attributeId: 6, attributeName: "Address Line 1", attributeType: "String", isMandatory: false},
 {attributeId: 7, attributeName: "Address Line 2", attributeType: "String", isMandatory: false},
 {attributeId: 8, attributeName: "City", attributeType: "String", isMandatory: false}]


    for (let index = 0; index < customerAttribute.length; index++) {

        console.log(customerAttribute[index].attributeId)
        console.log(customerAttribute[index].attributeName)

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM