简体   繁体   English

jQuery click事件上的jQuery Datatable访问行数据(render参数)

[英]jQuery Datatable access row data ( render parameter ) on jQuery click event

I have created link in datatable as: 我已经在数据表中创建链接为:

$('#example').dataTable( {
    "columnDefs": [ {
        "targets": 1,
        "render": function ( data, type, full, meta ) {
            return '<a href="'+data+'" data-id="'+full.id+'">Download</a>';
         }
      } ]
} );

I can access id on clicking <a> tag using jQuery click event, but I have several fields to access. 我可以使用jQuery click事件单击<a>标记来访问id ,但是我要访问几个字段。 And I don't want to use data- attribute to access each field. 而且我不想使用data- attribute访问每个字段。

How can I access row object ie( full ) , in jQuery event ? 如何在jQuery事件中访问行对象ie( full

What I have tried is: 我试过的是:

"render": function ( data, type, full, meta ) {
    alert(full);
    return '<a href="'+data+'" data-full="'+full+'">Download</a>';
}

In jQuery event alert( $(this).data('full') ); 在jQuery事件alert( $(this).data('full') ); I can see only [Object object] . 我只能看到[Object object]
I have tried to convert it to String but no success. 我试图将其转换为String,但没有成功。

Use row().data() API method to get data for any given row. 使用row().data() API方法获取任何给定行的数据。

For example: 例如:

$('#example').on('click', 'tbody a', function(){
   var $tr = $(this).closest('tr');
   var data = table.row($tr).data();
   console.log(data);
});

See this example for code and demonstration. 有关代码和演示,请参见此示例

Try jquery .data() to set / get data 尝试jquery .data()设置/获取数据

$(your_component).data("full", full)

or 要么

JSON.stringify(full) // convert json to string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM