javascript - 使用 $.parseJson() datatables.js 添加 aocolumns

标签 javascript jquery json datatables

我需要用来自服务器的 json、aaDataaoColumns 填充表格,但问题是我需要一个带有按钮的列。

我有这个代码

$('#divGrid').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>');

var results = result.split('@_@');
$('#example').dataTable({
    "aaData": $.parseJSON(results[0]),

    ,
    "aoColumns": $.parseJSON(results[1])
});
}

我的结果是

results[0] = "[["
jpa ","
SI ","
","
","
","
PADILLA ",1],["
sid ","
SI ","
","
","
","
MIRAMONTES ",2]]"

results[1] = [{
    "sTitle": "UserName"
}, {
    "sTitle": "ID_CENTRO_TRABAJO"
}, {
    "sTitle": "rolName"
}, {
    "sTitle": "dominio"
}, {
    "sTitle": "recibeAlertas"
}, {
    "sTitle": "NOMBRE"
}, {
    "sTitle": "edit",
    "fnRender": 'function(obj){ return ' < input type = 'button'
    name = 'hola'
    value = 'Play' > < /input>';}'}]" 

但是我的控制台很干净,没有抛出任何错误。该值出现,但按钮未出现。

最佳答案

您在返回和封装属性中使用相同的单引号,对属性使用双引号

return '<input  type="button" name="hola" value="Play">';

关于javascript - 使用 $.parseJson() datatables.js 添加 aocolumns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18551909/

相关文章:

javascript - 使用ajax在按钮单击上显示表格

javascript - 带有 eval() 的 Javascript 模块;

javascript - 根据父级的当前宽度将元素附加到父级和位置

java - RESTful 服务能否根据请求 header 为同一资源同时返回 JSON 和 XML?

javascript - 显示/隐藏 html 表的加载消息

javascript - .htaccess AddType 不起作用

javascript - 我应该如何从js中的多个跨度中获取 'This is my name '?

javascript - 错误 : Your listing cannot contain javascript (".cookie", "cookie("、 "replace("、IFRAME、META 或包含)、cookie 或基本 href

javascript - 为什么 JavaScript 解析器接受 JSON 作为函数体?

Javascript 递归标准化 JSON 数据