In my React/JS project, user checkes one or more of 3 option which user wants to see that type of data . These data types are final, generation, and availability. All of these 3 data types has different url's. I need to send request these data types which are checked in the form, I will not send the request to the unchecked one. I need a logic to check which one is selected and which one is unselected. I'm holding these data type states in an array named datatypes like this.
{
"id":"final",
"isChecked": false
},
{
"id":"generation",
"isChecked": false
},
{
"id":"availability",
"isChecked": false
}
]
I'm changing the state of isChecked property true, or false. And finally ı need to make a check and send request the isChecked= true ones. But ı dont want to do this operation like this:
**if**(datatypes[0].isChecked===**true** && datatypes[1].isChecked===**true** && datatypes[0].isChecked===**true**){
//request for 3 of data type
}
**else if**(datatypes[0].isChecked===**true** && datatypes[1].isChecked===**true** && datatypes[0].isChecked===**false**){
//request for first two data type(final, generation) and not for the 3. one
}
**else if**()...
It is exactly not the correct way to make this check. so what is the best and short logic for this situation? I'll be really greatful for every help and advice, Thx in advance :)
Aucun commentaire:
Enregistrer un commentaire