簡體   English   中英

如何在jQuery數據表中調用函數

[英]How to call Function in 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...");
        }
      })

在行中使用以下代碼

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;
     }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM