lundi 8 février 2021

Convert jQuery ternary operator to If else statement

I'm using jQuery, and there are two variables like viewChamina and approveChamina

var viewChamina = "<a onclick='viewSamana("
    + json.jdata[int].docset
    + ")'><button class=\"fa fa-eye\"></button></a>";
var approveChamina = "<a onclick='approveChamina("
    + json.jdata[int].docset
    + ")'><button class=\"fa fa-check\"></button></a>";

Below I'm using ternary operator to show viewChamina and(else) approveChamina

+"\<td>"
+(($(
"#srole")
    .val() === "ROLE_ADMIN") ? viewChamina : approveChamina )
+"\</td>"

I want to show approveChamina according to below condition, below you can see what I tried so far

 if(#srole").val() === "ROLE_ADMIN"){
     viewChamina 
 } else if(#srole").val() === "ROLE_USER"){
     approveChamina
 }

Aucun commentaire:

Enregistrer un commentaire