I got stuck in this problem.
I have 2 JSON data here :
List<ProductModel> prdctList
data: [
{
"name": "product 1",
"product_category": {
"id": 1,
"name": "Cat Food"
}
},
{
"name": "product 2",
"product_category": {
"id": 3,
"name": "Accesories"
}
}
]
List<prdctCtgrModel> prdctCtgrList
data : [
{
"id": 1,
"name": "Cat Food",
"pet_type": [
{
"id": 1,
"type": "Cat"
}
]
},
{
"id": 2,
"name": "Dog Food",
"pet_type": [
{
"id": 2,
"type": "Dog"
}
]
},
{
"id": 3,
"name": "Accesories",
"pet_type": [
{
"id": 1,
"type": "Cat"
},
{
"id": 2,
"type": "Dog"
}
]
}
]
I have a button to select pet_type, and the function I need is to filter product list with pet_type that I select. How to connect them with product_category from 2 data above?
example 1 :
example 2 :
I don't quite understand but isn't your problem solved by using a loop?
for (int i = 0; i < data.length; i++) {
List petTypes = data[i]["pet_type"].toList();
for (int j = 0; j < petTypes.length; j++) {
if (petTypes[j]["type"] == "Cat") {
print(data[i]);
// or do something, create new list
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments