I am getting below array of object from api response, i wanted to create one function which manipulate the data and enable and disable the flag based on below condition.
API Response
const data = [
{
"subfamily": "Hair Liquids (Includes: Bottles & Tottles, Tubes, Jars & Pouches)",
"status": "New",
"remainingTime": 6,
},
{
"subfamily": "Skin Care - Liquids (Includes: Bottles & Tottles, Tubes, Jars & Pouches)",
"status": "Submitted",
"remainingTime": 6
},
{
"subfamily": "Styling",
"status": "New",
"remainingTime": 6
}
];
Based on below cases, we need to enable/Disbale flag inside code.
- If all object status is new and remainingTime > 0, than isButtonEnable Flag
is True. - If any 2 object is submitted status and third object is New
status and remainingTime > 0 than, isButtonEnable flag True. - If any 1 object is submitted status, and other 2 object is New status and remainingTime < 0, than, isButtonEnable flag False.
- If any 1 object is submitted status,and other 2 object is New status and remainingTime > 0 than, isButtonEnable flag True.
Can anyone help me to check this condition and enable/Disable the flags.
Below is my code which i Tried
enableFlagOnStatus(){
if(data.length > 1){
data.forEach((currentValue, index) => {
if(currentValue.status ==='New' && remainingTime > 0){
this.isButtonEnale = True;
} else if(currentValue.status ==='Submitted' && remainingTime < 0){
this.isButtonEnale = False;
}
});
}
}
2
Answers
Try with this
Here is a code based on your condition.