Boolean returned by Web Method and added to row as data attribute is undefined

23 Views Asked by At

I have a function which loops through each element of an array returned by a Web Method and it works fine. In the loop an array Boolean value called HasLinkedReferrals is evaluated so 1 or 0 should be added to a row in a table as a data attribute called 'hasReferrals', then the row gets appended to a table body. It seems as though the 1s and 0s aren't being added as data attributes as intended, even though adding an alert or a console.log() demonstrates that they are present. Clicking on a click event for the class editTPLink has the value for hasReferrals as undefined but I can't see why?

    $('body').on('click', '.editTPLink', function (evt) {
       evt.preventDefault();
       var $this = $(this);
       var hasReferrals = $this.closest('tr').data('hasReferrals');
       alert(hasReferrals);     
    });

function InsertTimedPathwayRow(timedPathwayArray) {
   var isEnabled, tbody, css, linkText, tr, tdS, tdE, hasRefs
   $.each(timedPathwayArray.d, function (index, value) {
      isEnabled = value.IsDisabled == 0;
      tbody = isEnabled ? $('#tblActiveTimedPathways tbody') : $('#tblInactiveTimedPathways tbody');
      css = isEnabled ? 'fifteenpercentWidth' : 'twentypercentWidth';
      linkText = isEnabled ? 'Disable' : 'Enable';
      tr = $('<tr></tr>');
      tdS = '<td class="' + css + '">';
      tdE = '</td>';
      tr.append('<td class="thirdWidth">' + value.TimedPathwayName + tdE);
      tr.append('<td>' + value.TimedPathwayVersionNumber + tdE);
      tr.append(tdS + '<a href="#" runat="server" id="aViewEventsLink" class="viewEventsLink">View Events</a>' + tdE);
      if (isEnabled) { $('#tpEditLink').addClass('.hiddenColumn'); }
      if (isEnabled) { tr.append(tdS + '<a href="#" runat="server" id="aEditTPLink" class="editTPLink">Edit</a>' + tdE); }
      tr.append(tdS + '<a href="#" runat="server" id="aCopyTPLink" class="copyTPLink">Copy</a>' + tdE);
      tr.append(tdS + '<a href="#" runat="server" id="enableDisableTPLink" class="enableDisableTPLink">' + linkText + '</a>' + tdE);
      hasRefs = value.HasLinkedReferrals == true ? 1 : 0;
      tr.data({ 'timedPathwayID': value.TimedPathwayID, 'hasReferrals': hasRefs }); 
      tbody.append(tr);     
   });
}
0

There are 0 best solutions below