我有一个填充了aaData
的数据表,它描述了用户创建的任务。现在,数据表中有一个action
列,有两个或三个操作按钮或pdf等徽标 - 查看该任务的用户指南,浏览链接获取任务的源代码,其中一个是贡献者徽标哪个onclick应该显示该特定任务的贡献者。
aaData
采用以下格式填充表格
"aaData": [
[
"JSAG Home Page",
"JSAG Home page contains information about various POCs done",
"05/12/2012",
[
{
"displayValue":"Browse",
"link":"http://myTask.com/home",
"displayIcon" : "browselogo"
},
{
"displayValue":"Source Code",
"link":"svn/HomePage/trunk/",
"displayIcon" : "svnlogo"
},
{
"displayValue":"Audience Overview",
"link":"svn/Documents/Audience Overview.pdf",
"displayIcon" : "pdflogo"
},
{
"displayValue":"Contributors: ABC,XYZ",
"link":"#",
"displayIcon" : "people"
}
],
],
[
"Backlog",
"Backlog Forum application is designed to provide a platform for different groups to maintain backlog task items. ",
"25/08/2012",
[
{
"displayValue":"Browse",
"link":"http://mytask.com/BacklogApp",
"displayIcon" : "browselogo"
},
{
"displayValue":"Source Code",
"link":"svn/trunk/webapp-project/",
"displayIcon" : "svnlogo"
},
{
"displayValue":"Contributors: ABC",
"link":"#",
"displayIcon" : "people"
}
],
]
]
此格式适用于所有数据表和贡献者徽标。我想要的是,当用户点击贡献者图标时,他应该能够看到这些贡献者"ABC, XYZ, PQR"
。
我想要获取操作列数据,然后$each()
contributors
数组,但我无法继续操作。
我怎样才能实现这个目标?如何获取列值onclick
,因为每个数据表都是动态填充的。
请帮忙。
以下是填充贡献者div的代码
$(document).on('click', '#contributor', function(contributors){
$.each(contributors, function(i, data) {
var ul_data = "<li><h3>"+ data+ "</h3></li>";
$("#contributors_div").append(ul_data);
});
}
$('#contributors_div').show();
});
我如何获得recentActdata
作为我的贡献者JSON数组
答案 0 :(得分:1)
如果您在变量oTable中声明数据表
,它将与此类似$(document).on('click', '#contributor', function(){
var aPos = oTable.fnGetPosition( $(this) );
console.log(aPos);
//if aPos returns an array in console, use first val at pos zero to get row data
var aData = oTable.fnGetData(aPos[0]);
console.log(aData);
// inspect your returned object, then tailor your $.each iteration
$.each( aData["contributors"], function(i, data) {
var ul_data = "<li><h3>"+ data+ "</h3></li>";
$("#contributors_div").append(ul_data);
});
}
$('#contributors_div').show();
});