2017-10-16 24 views
1

我有這幾行代碼。我想爲某一行添加函數。點擊後,它會運行另一個功能。但它不識別函數聲明。如何在單擊某行時調用函數?以及如何將參數發送到與該行關聯的功能。該行中如何調用JQuery中的函數Datatable

$(document).ready(function() { 
     var restVul = function() { 
     alert("tik"); 
     } 

     $.ajax({ 
     url: "https://localhost:450/rest/products?pageNumber=1&pageCount=80", 
     type: "POST", 
     dataType: "json", 
     headers: { 
      'Content-Type': 'application/json' 
     }, 
     traditional: true, 
     contentType: "application/json; charset=utf-8", 
     processData: false, 
     data: JSON.stringify(hostAddresses), 
     success: function(response) { 
      console.log(response); 
      for (var i = 0; i < response.length; i++) { 
      var trHTML = ''; 
      for (var j = 0; j < response[i].Products.length; j++) { 
       trHTML += '<tr class="clickable-row" data-href="index.html"><td>' + response[i].IP + '</td><td onclick="function() {alert(); }">' + response[i].Products[j].Product + '</td><td>' + response[i].Products[j].CVECount + '</td></tr>'; 
      } 
      $('#ProductsTableBody').append(trHTML); 
      } 

      $('.js-exportable').DataTable({ 
      dom: 'Bfrtip', 
      responsive: true, 
      buttons: [ 
       'copy', 'csv', 'excel', 'pdf', 'print' 
      ] 
      }); 
     }, 
     error: function(xhr) { 
      console.log("Hata Oluştu..."); 
     } 
     }) 

回答

0

使用下面的代碼

columns: [ 
{"data": "xxx", "width": "10%","visible": false, "render": function (data, type, row, meta) { } }, 
] 

使用下面的函數內部代碼,以使在列可點擊的鏈接

if (type === 'display') { 
     return $('<a>') 
     .attr('href', ' ') 
     .text(data) 
     .wrap('<div></div>') 
     .parent() 
     .html(); 
    } else { 
      return data; 
    } 
+0

是否有加東西​​項目的任何其他方式? –

+0

你想做什麼告訴我你的使用案例我會幫你 –

+0

我想添加onclick事件到​​ –