我在数据库中有一个输出此JSON的表:
{"sEcho":1,
"iTotalRecords":7,
"iTotalDisplayRecords":7,
"aaData":[
{"FormID":"6",
"FormName":"Configuration",
"FormPath":"#","FormCIPath":"#"},
{"FormID":"1",
"FormName":"Dashboard",
"FormPath":"#",
"FormCIPath":"admin\/dashboard\/System"}],
"sColumns":"FormName,FormPath,FormCIPath"}
但是我没有在数据表中给出FormID中的任何列,因为我不想将数据库的FormID显示为公共。
但我怎样才能获得FormID?
这是Javascript:
<script>
$(document).ready(function() {
var oTable = $('#ManageForms').dataTable({
"bServerSide":true,
"bProcessing":true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bFilter":true,
"sServerMethod": "POST",
"sAjaxSource": "{{base_url()}}admin/configurations/listForms_DT/",
"iDisplayLength": 2,
"aLengthMenu": [[2, 25, 50, -1], [2, 25, 50, "All"]],
"sEcho": 1,
"columns":[
{data:"FormName"},
{data:"FormPath"},
{data:"FormCIPath"},
{ "data": null,
"defaultContent": "<a href='#editBtnModal' class='editBtnFunc' ><i style='color: #666666' class='fa fa-pencil fa-fw fa-2x'></i></a><a href='#' id='deleteBtn'><i style='color: #ff0000' class='fa fa-times fa-fw fa-2x'></i></a>",
"targets": -1
}
],
'fnServerData' : function(sSource, aoData, fnCallback){
$.ajax ({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
}); //end of ajax
}
});
//Edit Button on Modal Window
$('#ManageForms').on('click', '.editBtnFunc', function(e){
e.preventDefault();
//var aPos = oTable.fnGetPosition( this );
//var aData = oTable.fnGetData( aPos[0] );
console.log(oTable);
});
//Edit Button
} );
</script>
这是HTML
<div class="row ui-sortable">
<div class="col-lg-12">
<div class="box">
<header>
<div class="icons">
<i class="fa fa-table"></i>
</div>
<h5>Manage Forms</h5>
</header>
<div class="body" id="collapse4">
<table id="ManageForms" class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Form Name</th>
<th>Form Path</th>
<th>Form CI Path</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
为了获得fnGetPosition(this),你应该点击表格中的TR,TD或TH。你可以找到最近的“.editBtnFunc”标签的td或tr,并获得行的位置。
$('#ManageForms').on('click', '.editBtnFunc', function(e){
var row = $(this).closest('tr');
var aPos = oTable.fnGetPosition( row );
var aData = oTable.fnGetData( aPos[0] );
});