当前位置: 首页 > 知识库问答 >
问题:

如何通过linq[duplicate]获取数组项

饶志
2023-03-14
Variables.PolicyCustomerAddresses

(3) [{…}, {…}, {…}]
0: {ADRES_EK: null, ADRES_ID1: 885843,  ADRES_TEXT: "XXXX", MUSTERI_ADRES_ID: "333", …}

1: {ADRES_EK: null, ADRES_ID1: 890997, ADRES_TEXT: "YYYY", MUSTERI_ADRES_ID: "222", …}

2: {ADRES_EK: null, ADRES_ID1: 890902,  ADRES_TEXT: "ZZZZ", MUSTERI_ADRES_ID: "111", …}
length: 3

correspondenceAdress == 222

像这样,我想通过linq获得whomusteri_adres_id==222

var adreeess = Variables.PolicyCustomerAddresses;
                var adrx = Enumerable.From(adreeess)
                        .Where("$.MUSTERI_ADRES_ID === correspondenceAdress ")
                        .FirstOrDefault(null)
                        .First();

共有1个答案

东方新霁
2023-03-14

musteri_adres_id必须是字符串,作为给定数据中的值。

var Variables = { PolicyCustomerAddresses: [{ ADRES_EK: null, ADRES_ID1: 885843,  ADRES_TEXT: "XXXX", MUSTERI_ADRES_ID: "333" }, { ADRES_EK: null, ADRES_ID1: 890997, ADRES_TEXT: "YYYY", MUSTERI_ADRES_ID: "222" }, { ADRES_EK: null, ADRES_ID1: 890902,  ADRES_TEXT: "ZZZZ", MUSTERI_ADRES_ID: "111" }] },
    correspondenceAdress = "222", // string!
    result = Enumerable.From(Variables.PolicyCustomerAddresses)
        .Where("$.MUSTERI_ADRES_ID === correspondenceAdress")
        .DefaultIfEmpty(null)
        .First();

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.js"></script>
 类似资料: