我在项目中使用了dataTable,并使用编辑和删除按钮为其添加了一个自定义列。我能够将各个字段传递给函数。是否可以将object作为参数传递给函数?
以下是我的dataTable代码:
<script type="text/javascript">
var table1;
$(function(){
table1 = $('#simpletable').DataTable({
processing :true,
serverSide :true,
//table: '#simpletable',
ajax :"{{route('shippingPreference.create')}}",
columns :[
// { data: "id" },
{ data: "channel_name" },
{ data: "process_type" },
{ data: "method_name" },
{ data: "market_place_shipping_method_name" },
{
sortable: false,
"render": function ( data, type, full, meta ) {
console.log(full);
var actionhtml='<button data-toggle="tooltip" data-placement="top" id="'+full.id+'" title="Remove" type="button" class="btn btn-danger btn-xs" >' +
'<i class="fa fa-times-circle" aria-hidden="true"></i></button><a data-toggle="tooltip" data-placement="top" data-original-title="Edit" class="btn btn-info btn-xs" onclick="callMe('+full+')">'+
'<i class="fa fa-edit" aria-hidden="true"></i></a>';
return actionhtml;
}
}
],
} );
});
答案 0 :(得分:0)
正如@markpsmith所说,你必须使用JSON.stringify(full)
并在你的代码中使用单引号而不是双引号:
var actionhtml='<button data-toggle="tooltip" data-placement="top" id="'+full.id+'" title="Remove" type="button" class="btn btn-danger btn-xs" >' +
'<i class="fa fa-times-circle" aria-hidden="true"></i></button><a data-toggle="tooltip" data-placement="top" data-original-title="Edit" class="btn btn-info btn-xs" onclick=\'callMe('+JSON.stringify(full)+')\'>'+
'<i class="fa fa-edit" aria-hidden="true"></i></a>';