如何在本机反应中仅从数组中获取特定项目的数据

沿海谢赫

我的数据看起来像这样

这是子类别列表:

{
    "statusCode": 200,
    "status": "SUCCESS",
    "responseContents": [
        {
            "webimage": [],
            "appimage": [],
            "_id": "6155c2c77f31f9b79ba4273b",
            "Categories": "Tools & Machineries",
            "Subcategories": [
                "Power & Hand Tools ",
                "Plant Cutting tools",
                "All Tools & Home Improvement",
                "Tool Storage & Organization",
                "Tool Organisers",
                "Pneumatic Tools",
                "Carbide Cutting Tools",
                "Tool Storage & Organization",
                "Tools & Workshop Equipment",
                "TOOLS & EQUIPMENTS",
                "Hand Tools"
            ]
        },
        {
            "webimage": [],
            "appimage": [],
            "_id": "6155c2c77f31f9b79ba4273c",
            "Categories": "Furniture",
            "Subcategories": [
                "Wooden Furniture",
                "Office Furniture",
                "Kitchen Furniture",
                "Modular Office Furniture",
                "Industrial Furniture",
                "Steel Furniture",
                "Living Room Furniture",
                "|Storage and Display Furniture",
                "Entryway Furniture",
                "Inflatable Furniture",
                "Patio Furniture & Accessories",
                "Storage and Display Furniture",
                " Office & Commercial Furniture "
            ]
        },
        {
            "webimage": [],
            "appimage": [],
            "_id": "6155c2c77f31f9b79ba4273d",
            "Categories": "Safety & Security",
            "Subcategories": [
                "Industrial Safety Equipments",
                "Safety Equipment",
                "Fire Fighting Equipments",
                "Traffic Safety Equipment",
                "Marine Safety Equipment",
                "Welding Safety Accessories",
                "Work Safety Equipment & Gear",
                "PERSONAL PROTECTION EQUIPMENTS",
                "General Safety Equipment ",
                " Fire Fighting & Prevention Products ",
                "SAFETY MATERIALS (PPE)"
            ]
        },
        {
            "webimage": [],
            "appimage": [],
            "_id": "6155c2c77f31f9b79ba4273e",
            "Categories": "Lighting",
            "Subcategories": [
                "LED COMMERCIAL LIGHTING",
                "Panel Light",
                "Ceiling Lights",
                "Indoor Lighting ",
                "Flood Lights",
                "Lighting Fixtures ",
                "Lights & Fittings",
                " Indoor Lights & Lighting Accessories"
            ]
        }
        ...
    ]
}

现在我只想获取特定类别的数据。例如,我只想获取工具和机械类别的数据。我该怎么做,请帮忙

纳夫纳特

const data = {"statusCode":200,"status":"SUCCESS","responseContents":[{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273b","Categories":"Tools & Machineries","Subcategories":["Power & Hand Tools ","Plant Cutting tools","All Tools & Home Improvement","Tool Storage & Organization","Tool Organisers","Pneumatic Tools","Carbide Cutting Tools","Tool Storage & Organization","Tools & Workshop Equipment","TOOLS & EQUIPMENTS","Hand Tools"]},{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273c","Categories":"Furniture","Subcategories":["Wooden Furniture","Office Furniture","Kitchen Furniture","Modular Office Furniture","Industrial Furniture","Steel Furniture","Living Room Furniture","|Storage and Display Furniture","Entryway Furniture","Inflatable Furniture","Patio Furniture & Accessories","Storage and Display Furniture"," Office & Commercial Furniture "]},{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273d","Categories":"Safety & Security","Subcategories":["Industrial Safety Equipments","Safety Equipment","Fire Fighting Equipments","Traffic Safety Equipment","Marine Safety Equipment","Welding Safety Accessories","Work Safety Equipment & Gear","PERSONAL PROTECTION EQUIPMENTS","General Safety Equipment "," Fire Fighting & Prevention Products ","SAFETY MATERIALS (PPE)"]},{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273e","Categories":"Lighting","Subcategories":["LED COMMERCIAL LIGHTING","Panel Light","Ceiling Lights","Indoor Lighting ","Flood Lights","Lighting Fixtures ","Lights & Fittings"," Indoor Lights & Lighting Accessories"]}]};

function getBySubCategory(dataSet, category){
  return dataSet.find(o => o.Categories===category);
}

const dataSet = data.responseContents;
console.log(getBySubCategory(dataSet, 'Tools & Machineries'));
console.log(getBySubCategory(dataSet, 'Safety & Security'));
.as-console-wrapper { max-height: 100% !important; top: 0 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Java中获取枚举数组中特定项目的值?

如何在反应本机中获取参数

如何快速获取多维数组中特定项目的计数

如何获取多维(嵌套)数组中特定项目的索引?

如何在本机反应中呈现两列中的项目?

如何在本机反应中从 asyncStorage 中删除单个项目?

如何在反应中从 url 获取数组数据?

如何获取数组中项目的id

如何在本机反应中从数据库mysql获取图像数据

如何在平面清单中多选项目反应本机

如何在反应本机中使用特定索引更新数组中的值

如何在不按本机反应的情况下从异步存储中获取数据

如何在本机反应中一一显示数组中的元素

如何根据本机反应中的位置获取数据

如何在本机反应中向下滚动特定值?

如何在本机反应中获取子组件的状态

如何在本机反应中获取图像的高度?

如何在本机反应中获取 webview 内部?

如何在本机反应中显示来自哈希的数据?

AngularJS获取JSON数组中特定项目的长度

如何在Vue中的渲染列表中存储来自特定项目的数据属性值

如何在razor视图引擎中获取集合中项目的元数据?

获取春季数据表中特定项目的页码

VBA代码从清单中获取特定项目的数据等级

如何在本机项目中获取主目录中的文件?

如何在Swift中获取2个数组的不同(不常见)项目的列表

如何在Elasticsearch中获取所有项目的特定值

如何在Android中获取列表视图的特定项目的ID?

如何更改数组中特定项目的位置?