In my response which I receive from the service, each property represents different functionality that can be displayed on the screen based on user role. So if the property is set to "Yes" the divs and buttons associated with that functionality will be visible on the screen. It is also possible for all 3 properties as "Yes" or at least one as "YES" and the other two as "No" or the other two as "Yes" and one as "No". for example
res = {
"order" : "Yes"
"Enquiry" : "Yes"
"Status" : "No"
} or
res = {
"order" : "Yes"
"Enquiry" : "No"
"Status" : "No"
}
or
res = {
"order" : "No"
"Enquiry" : "Yes"
"Status" : "No"
}
or
res = {
"order" : "Yes"
"Enquiry" : "Yes"
"Status" : "Yes"
}
To achieve this basic way to write if else condition is
if( res.order == "Yes" )
{
this.displayOrder = "true"
}
else
{
this.displayOrder = "false" }
similarly, I need to write for all the properties. In future they may add more functionalities/ properties in JSON response and the code will be extending with a lot of if-else. What is the best approach or best coding practice to accomplish this logic?
Aucun commentaire:
Enregistrer un commentaire