第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Lodash過(guò)濾器給定具有多個(gè)條件的json數(shù)組

Lodash過(guò)濾器給定具有多個(gè)條件的json數(shù)組

翻閱古今 2023-08-18 14:28:50
我有一個(gè)如下所示的 json 數(shù)組,我使用 lodash 進(jìn)行過(guò)濾const data =  [    {      "id": "66b2bc0b-2486-4bb0-a93c-0337ebe1d647",      "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750",      "name": null,      "type": null,      "model": null,      "serial_number": null,      "mac_address": null,      "firmware_verison": null,      "gateway_id": null,      "device_code": "ST921WF-001E5E02C002",      "location_id": null,      "status": null,      "updated_at": "2020-11-17T07:05:57.037Z",      "created_at": "2020-11-17T07:05:57.037Z",      "created_by": null,      "updated_by": null    },    {      "id": "975c51f8-a6cb-4701-aaa6-077f8a9974a5",      "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750",      "location_id": null,      "type": null,      "name": null,      "model": null,      "status": null,      "serial_number": null,      "mac_address": null,      "firmware_verison": null,      "gateway_id": null,      "device_code": "ST921WF-001E5E02C001",      "created_by": null,      "updated_by": null,      "created_at": "2020-11-17T07:05:57.015Z",      "updated_at": "2020-11-17T07:05:57.167Z"    },    {      "id": "c4d5e446-c137-443c-a4d7-2c54c204c018",      "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",      "name": null,      "type": null,      "model": null,      "serial_number": null,      "mac_address": null,      "firmware_verison": null,      "gateway_id": null,      "device_code": "ST921TH-001E5E02C001_Naveen",      "location_id": null,      "status": "active",      "updated_at": "2020-11-18T12:10:56.027Z",      "created_at": "2020-11-18T12:10:56.027Z",      "created_by": null,      "updated_by": null    },  ]我需要根據(jù)多個(gè)條件過(guò)濾數(shù)組,例如從數(shù)據(jù)中過(guò)濾 { status: "active","type": "gateway"};它應(yīng)該返回滿足此條件的所有對(duì)象。where 條件應(yīng)該是動(dòng)態(tài)的,并且應(yīng)該接受任何支持的字段進(jìn)行過(guò)濾。我嘗試了以下但無(wú)法添加多個(gè)條件const filteredData = lodash.find(data, ['status', 'active']);有沒(méi)有辦法做到這一點(diǎn),如果可以,請(qǐng)幫我提供示例代碼
查看完整描述

1 回答

?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

要過(guò)濾數(shù)據(jù),您可以使用filterlodash 庫(kù)的方法。我附上了一個(gè)代碼片段。希望這有助于解決問(wèn)題。


const data = [{

    "id": "66b2bc0b-2486-4bb0-a93c-0337ebe1d647",

    "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750",

    "name": null,

    "type": null,

    "model": null,

    "serial_number": null,

    "mac_address": null,

    "firmware_verison": null,

    "gateway_id": null,

    "device_code": "ST921WF-001E5E02C002",

    "location_id": null,

    "status": null,

    "updated_at": "2020-11-17T07:05:57.037Z",

    "created_at": "2020-11-17T07:05:57.037Z",

    "created_by": null,

    "updated_by": null

  },

  {

    "id": "975c51f8-a6cb-4701-aaa6-077f8a9974a5",

    "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750",

    "location_id": null,

    "type": null,

    "name": null,

    "model": null,

    "status": null,

    "serial_number": null,

    "mac_address": null,

    "firmware_verison": null,

    "gateway_id": null,

    "device_code": "ST921WF-001E5E02C001",

    "created_by": null,

    "updated_by": null,

    "created_at": "2020-11-17T07:05:57.015Z",

    "updated_at": "2020-11-17T07:05:57.167Z"

  },

  {

    "id": "c4d5e446-c137-443c-a4d7-2c54c204c018",

    "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",

    "name": null,

    "type": null,

    "model": null,

    "serial_number": null,

    "mac_address": null,

    "firmware_verison": null,

    "gateway_id": null,

    "device_code": "ST921TH-001E5E02C001_Naveen",

    "location_id": null,

    "status": "active",

    "updated_at": "2020-11-18T12:10:56.027Z",

    "created_at": "2020-11-18T12:10:56.027Z",

    "created_by": null,

    "updated_by": null

  },

  {

    "id": "9287ce48-e60b-4e8a-96a5-cbedd1ee3be2",

    "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",

    "name": null,

    "type": "smart-plug",

    "model": null,

    "serial_number": null,

    "mac_address": null,

    "firmware_verison": null,

    "gateway_id": null,

    "device_code": "ST921TH-001E5E02C002",

    "location_id": null,

    "status": null,

    "updated_at": "2020-11-18T12:11:21.867Z",

    "created_at": "2020-11-18T12:11:21.867Z",

    "created_by": null,

    "updated_by": null

  },

  {

    "id": "6bf58e90-6a84-480e-b944-2cabb90f60c9",

    "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",

    "name": null,

    "type": "gateway",

    "model": null,

    "serial_number": null,

    "mac_address": null,

    "firmware_verison": null,

    "gateway_id": null,

    "device_code": "ST921GW-001E5E02C002",

    "location_id": null,

    "status": "active",

    "updated_at": "2020-11-18T12:12:23.431Z",

    "created_at": "2020-11-18T12:12:23.431Z",

    "created_by": null,

    "updated_by": null

  }

];

const filteredData = _.filter(data, {

  status: "active",

  type: "gateway"

})

console.log(filteredData);

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>


查看完整回答
反對(duì) 回復(fù) 2023-08-18
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)