javascript - 从 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)
}
推荐阅读
- ruby - 订阅生成错误的条带更新
- javascript - 使用onchange事件时如何使选择字段成为必需
- c++ - 如何将 std::to_string 函数的预填充归零?
- amazon-web-services - 托管静态网页时拒绝 Amazon s3 存储桶策略访问
- c# - 将多个选定的列表框项目保存到数据库中的单独行
- java - 如何管理多个 Android 库项目的公共依赖项?
- visual-studio - 子分支项目未显示在 TFS 服务器中
- c# - 如何从 2 ViewModel WPF 绑定数据
- html - 播放框架:如何用静态 js 和 css 渲染静态 HTML 页面?
- c# - ASP.NET MVC 5 和 WCF 异步问题