Pergunta

I have been trying to do an if else condition in the append method however for some reason it's not reading the condition. Here is the code. Towards the bottom I want to show signNow if the list item field is blank else show theForm (which is html that I assigned to a variable):

functionData();

function functionData(){
        var urlParam = GetUrlKeyValue("ID");       
        var method = "GetListItems";                 
        var webURL =  $().SPServices.SPGetCurrentSite();                     
        var list = "signature3";
        var fieldsToRead = "<ViewFields>"+"<FieldRef Name='ID' />" +"</ViewFields>";
        var query = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + urlParam + "</Value></Eq></Where></Query>";                       

        $().SPServices
        ({
            operation: method,
            async: false, 
            webURL: webURL,
            listName: list,
            CAMLViewFields: "<ViewFields Properties='True' />",
            CAMLQuery: query,                                                                                     
            completefunc: function (xData, Status)
            {
                $(xData.responseXML).SPFilterNode("z:row").each(function() 
                 {
                    var signNow = $(this).attr("ows_signature1");
                    var author = $(this).attr("ows_Author");
                    var created =  $(this).attr("ows_Created");
                    var author = author.slice(6);
                    var theForm = " <a id=\"create-user\" href=\"#\">Sign</a>"

                    $("#myHTMLTable").append("<tr>" +
                    "   <td width=\"50%\" style=\"font-size: 12pt;\">" +
                    "       Created:  " + created +
                    "   </td>" + 
                    "   <td width=\"50%\" style=\"font-size: 12pt;\">" +
                    "       By:  " + author +
                    "   </td>" +
                    "</tr>" +
                    "<tr>" +
                    "   <td width=\"50%\" class=\"tdHeader\">" +
                    "       Contracting Officer Representative (COR) Processing" +
                    "   </td>" +
                    "   <td width=\"50%\" class=\"tdSig right\">" +
                    //I want to "signNow" if the field is not blank else "theForm" if it's blank
                    signNow +
                    "</td>" +
                    "</tr>");
                });
            }
       });  
};

            </script>
Foi útil?

Solução

Try replacing

signNow +

with

((signNow) ? signNow : theForm) +

You can read more about ternary operator here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top