亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

使用'AND”、'OR”運(yùn)算符搜尋 Json 對(duì)象
P粉029327711
P粉029327711 2023-09-06 10:23:16
0
1
792

我遇到一個(gè)問(wèn)題,需要使用條件運(yùn)算子字串搜尋 JSON 物件。

JSON 物件看起來(lái)像

let Data = [
  {Application: 'APIM', Owner: 'Vande Mataram','Customer Code': 'DJLFKASJF',Environment: 'Dev',OS: 'Linux',Region: 'EU','TEAM ': 'DemoTestCOE'},
  {TEAM: 'BCC'},
  {Team: 'DemoTestCOE','Customer Code': 'DJLFKASJF',Owner: 'Vande Mataram',Environment: 'Prod',Region: 'EU',Application: 'Ui-Path',OS: 'Windows'},
  {Application: 'MGMT','Customer Code': 'DJLFKASJF', os: 'Windows','Owner ': 'Vande Mataram', Region: 'East US 2',Team: 'DemoTestCOE',Environment: 'MGMT'  },
  {Application: 'PIER',Owner: 'Govindarajulu Balaji',OS: 'Windows',Region: 'DemoTestCOE', Environment: 'QA'}  
]

以及如下所示的條件字串..

let condition =
  '"Owner": "Vande Mataram" AND ("Application": "APIM" AND "Customer Code": "DJLFKASJF") OR ("Owner": "Vande Mataram" AND "Customer Code": "DJLFKASJF") OR "Owner": "Vande Mataram"'

沒(méi)有網(wǎng)路的運(yùn)氣...如何實(shí)現(xiàn)這個(gè),我無(wú)法將其帶到 SQL Server,因?yàn)樗枰?javascript 中完成。

我在網(wǎng)路上搜尋了將條件字串拆分為按運(yùn)算子(AND/OR)拆分的數(shù)組,並在json資料物件中進(jìn)行一一搜索,但是每個(gè)請(qǐng)求的條件字串都不同。並且努力正確實(shí)施運(yùn)算符(AND/OR)。我不確定這是最好的主意

我需要幫助如何解決這個(gè)問(wèn)題以滿足使用多個(gè)嵌套括號(hào)提供的任何類型的條件。

謝謝

P粉029327711
P粉029327711

全部回覆(1)
P粉174151913

Data 只是一個(gè)物件數(shù)組,因此您可以使用 Array.filter

let Data = [
  {Application: 'APIM', Owner: 'Vande Mataram','Customer Code': 'DJLFKASJF',Environment: 'Dev',OS: 'Linux',Region: 'EU','TEAM ': 'DemoTestCOE'},
  {TEAM: 'BCC'},
  {Team: 'DemoTestCOE','Customer Code': 'DJLFKASJF',Owner: 'Vande Mataram',Environment: 'Prod',Region: 'EU',Application: 'Ui-Path',OS: 'Windows'},
  {Application: 'MGMT','Customer Code': 'DJLFKASJF', os: 'Windows','Owner ': 'Vande Mataram', Region: 'East US 2',Team: 'DemoTestCOE',Environment: 'MGMT'  },
  {Application: 'PIER',Owner: 'Govindarajulu Balaji',OS: 'Windows',Region: 'DemoTestCOE', Environment: 'QA'}  
]
// and the condition string like below..
/*
let condition =
  '"Owner": "Vande Mataram" AND ("Application": "APIM" AND "Customer Code": "DJLFKASJF") OR ("Owner": "Vande Mataram" AND "Customer Code": "DJLFKASJF") OR "Owner": "Vande Mataram"'
*/
console.log(Data.filter(item => {
    return item.Owner === 'Vande Mataram' 
    && (item.Application === "APIM" && item['Customer Code'] === "DJLFKASJF") 
    || (item.Owner === 'Vande Mataram' && item['Customer Code'] === "DJLFKASJF")
    || item.Owner === 'Vande Mataram';
}));
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板