jquery对复杂的集合型Json数据进行筛选(象C#的find一样)

比如如下js下的json数据:

var list=[
{"ColName":"OrderDate","ColLabel":"日期","ColNewLabel":"日期","IsChecked":1,"Sort":"0"},
{"ColName":"OrderCode","ColLabel":"单据编号","ColNewLabel":"单据编号","IsChecked":0,"Sort":"888"},
{"ColName":"TypeName","ColLabel":"类型","ColNewLabel":"类型","IsChecked":1,"Sort":"0"},
{"ColName":"CustomerName","ColLabel":"客户名称","ColNewLabel":"客户名称","IsChecked":1,"Sort":"0"},{"ColName":"FieldText1","ColLabel":"undefined","ColNewLabel":"undefined","IsChecked":0,"Sort":"0"},
{"ColName":"SellerName","ColLabel":"销售人员","ColNewLabel":"销售人员","IsChecked":0,"Sort":"0"},
{"ColName":"TrailStatus","ColLabel":"跟进状态","ColNewLabel":"跟进状态","IsChecked":1,"Sort":"0"},
{"ColName":"CreateUserName","ColLabel":"制单人员","ColNewLabel":"制单人员","IsChecked":0,"Sort":"0"},
{"ColName":"Description","ColLabel":"备注说明","ColNewLabel":"备注说明","IsChecked":1,"Sort":"0"}
]

要求筛选中ColName为“SellerName"的实体对象:

var getlist = data.filter((item) => item.ColName == ”SellerName“);

结果为:[{"ColName":"SellerName","ColLabel":"销售人员","ColNewLabel":"销售人员","IsChecked":0,"Sort":"0"}]

也可以模糊查询:

var getlist = data.filter((item)=>item.ColLabel.includes(qstring));//qstring就是你搜索的关键字

 

posted @ 2023-09-08 09:34  James·wang  阅读(161)  评论(0编辑  收藏  举报