我是初学者,我正在尝试在where
上实现List
来过滤数据,但我完全错了,请指导我正确的实现方式
实施
List filterproducts= productslist.where(widget.bomdatareceived[0]['purchase_items'][0]['product_code'].contains(widget.product_code));
错误
type 'bool' is not a subtype of type '(dynamic) => bool'
JSON数据
"purchase_items": [
{
"product_code": "61",
"name": "SPINNING",
"bom_catalog_item": "327",
},
{
"product_code": "61",
"name": "SPINNING",
"bom_catalog_item": "390",
},
{
"product_code": "65",
"name": "DYING",
"bom_catalog_item": "1056",
}
]
答案 0 :(得分:0)
List filterproducts= productslist.where((i) => widget.bomdatareceived[0]['purchase_items'][0]['product_code'].contains(widget.product_code));
答案 1 :(得分:0)
List filterproducts= productslist.where((f) => f.bomdatareceived[0]['purchase_items'][0]['product_code'].contains(widget.product_code)).toList();
答案 2 :(得分:0)
var filterproducts=[];
filterproducts.addAll(widget.bomdatareceived[0]['purchase_items'][0]['product_code']
.where((element) => element.contains(widget.product_code))
.toList());
答案 3 :(得分:0)
结果:
代码:
var purchase_items = [
{
"proc_code": "61",
"name": "SPINNING",
"bom_catalog_item": "327",
},
{
"proc_code": "61",
"name": "SPINNING",
"bom_catalog_item": "390",
},
{
"proc_code": "65",
"name": "DYING",
"bom_catalog_item": "1056",
}
];
List<Map<String,String>> filterproducts = new List<Map<String,String>>();
filterproducts = purchase_items.where((f) => f['proc_code'] == ('61')).toList();
print(filterproducts);