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的MUSTERI_ADRES_ID == 222
代替
var adreeess = Variables.PolicyCustomerAddresses;
var adrx = Enumerable.From(adreeess)
.Where("$.MUSTERI_ADRES_ID === correspondenceAdress ")
.FirstOrDefault(null)
.First();
答案 0 :(得分:1)
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>