Cannot append Table Rows to dynamically created Table Rows

Cannot append Table Rows to dynamically created Table Rows

Hi,

i am looping through a JSON response and creating and table with an image in each row. When the user clicks on this icon, i start another ajax call and get the child results for this row.

I see the result in the console when i do a console.log.

But i am not able to do an .append on the .closest("tr"). Whats is wrong here? Here is my code:

 

  1.     $(document).ready(function () {
  2.         var url = location.protocol + "//" + location.host + L_Menu_BaseUrl;
  3.         var JSONService = url + "/_vti_bin/GPExt/GPService.svc";
  4.         $.getJSON(JSONService + "/GetTeil", function (data) {
  5.             //
  6.         })
  7.         .done(function (data) {
  8.             if ((data !== undefined) && (data !== null)) {
  9.                 var htmlTable = "<table id=\"tblGP\" style=\"width:100%;border:1px solid #ccc;\">";
  10.                 htmlTable += "<tr>";
  11.                 htmlTable += "<th>Location</th>";
  12.                 htmlTable += "</tr>";
  13.                 $.each(data.GetTeilResult, function (i, item) {
  14.                     htmlTable += " <tr>";
  15.                     htmlTable += " <td colspan=\"16\"><img id=\"expandteil\"
  16. rc=\"/_layouts/images/GpExt/plus.png\" />&nbsp;" + item.teile + "</td>";
                        htmlTable += " </tr>";
  17.                 });
  18.                 htmlTable += "</table>"; 
  19.         $(htmlTable).appendTo("#mainDataTable");
  20.           
  21.          $("#expandteil").click(function () {
  22.                     $.getJSON(JSONService + "/GetNachw/" + encodeURIComponent('bog, ya'), function (data) {
  23.                         //
  24.                     })
  25.                     .done(function (data) {
  26.                         if ((data !== undefined) && (data !== null)) {
  27.                             var row = $(this).closest("tr");
  28.                             $.each(data.GetNachwResult, function (j, itemNachw) {
  29.                                 var htmlRow = "<tr>";
  30.                                 htmlRow += "<td colspan=\"16\"><img id=\"sad\" src=\"/_layouts/images/GPExt/plus.png\" />" + itemNachw.Bezeichnung + "</td>";
  31.                                 htmlRow += "</tr>";
  32.                                 $(row).append(htmlRow);
  33.                             });                        
  34.                         } else {
  35.                             alert("Keine Nachw vorhanden!");
  36.                         };
  37.                     });
  38.                 });
  39.                 console.log("Finished teil ....")
  40.             } else {
  41.                 alert("Keine Daten vorhanden!");
  42.             };
  43.         });
  44.     });

 

var row = $(this).closest("tr");

is undefined

 

regards

Yavuz