Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript数据表在JSON数据上使用呈现函数生成HTML链接_Javascript_Html_Json_Datatables - Fatal编程技术网

Javascript数据表在JSON数据上使用呈现函数生成HTML链接

Javascript数据表在JSON数据上使用呈现函数生成HTML链接,javascript,html,json,datatables,Javascript,Html,Json,Datatables,我得到了一个html表格: <table id="dattable" class="table table-striped table-bordered hover" cellspacing="0" > <thead> <tr> <th>Name</th> <th>Industry</th> <th>Co

我得到了一个html表格:

<table id="dattable"  class="table table-striped table-bordered hover" cellspacing="0" >
    <thead>
        <tr>
            <th>Name</th>
            <th>Industry</th>
            <th>Cost</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

名称
工业
成本
它由JSON数据填充。我想使用该函数使用id字段使name列中的项目具有HTML链接,但它不起作用

var data2 =[
    {
        "id": "0",
        "name":       "Jack Spicer",
        "industry__name":   "System Architect",
        "cost":     "$3,120",
    },
    {
        "id":"1",
        "name":       "Sean Spice",
        "industry__name":   "Motormouth",
        "cost":     "-$5,300",
    }
];

$(document).ready(function() {
    var table = $('#dattable').DataTable( {
        data: data,
        columns: [
            { data: 'name', "render": "<a href =" + [, ].id +">"+[, ].name+"</a>"},  //render function
            { data: 'industry__name' },
            { data: 'cost' }
        ],


    } );
} );
var数据2=[
{
“id”:“0”,
“姓名”:“杰克·斯派塞”,
“行业名称”:“系统架构师”,
“成本”:“$3120”,
},
{
“id”:“1”,
“名称”:“肖恩香料”,
“行业名称”:“Motormouth”,
“成本”:“-5300美元”,
}
];
$(文档).ready(函数(){
变量表=$('#dattable')。数据表({
数据:数据,
栏目:[
{data:'name',“render”:“},//render函数
{数据:'行业名称'},
{数据:'成本'}
],
} );
} );

根据您的代码,我认为您需要更改生成所需自定义文本的列的定义。另外,我修改了对渲染的调用,以使用函数版本

var data2 = [{
    "id": "0",
    "name": "Jack Spicer",
    "industry__name": "System Architect",
    "cost": "$3,120",
}, {
    "id": "1",
    "name": "Sean Spice",
    "industry__name": "Motormouth",
    "cost": "-$5,300",
}];

$(document).ready(function() {
    var table = $('#dattable').DataTable({
        data: data2,
        columns: [{
          'data': null,
          'render': function(data, type, row, meta) {
            return '<a href=' + data.id + '>' + data.name + '</a>';
          }
        }, {
          data: 'industry__name'
        }, {
          data: 'cost'
        }]
    });
});
var数据2=[{
“id”:“0”,
“姓名”:“杰克·斯派塞”,
“行业名称”:“系统架构师”,
“成本”:“$3120”,
}, {
“id”:“1”,
“名称”:“肖恩香料”,
“行业名称”:“Motormouth”,
“成本”:“-5300美元”,
}];
$(文档).ready(函数(){
变量表=$('#dattable')。数据表({
数据:数据2,
栏目:[{
“数据”:null,
“呈现”:函数(数据、类型、行、元){
返回“”;
}
}, {
数据:“行业名称”
}, {
数据:“成本”
}]
});
});

您也可以在这方面做很多工作,看看我所做的更改:

我同意,很乐意为您提供帮助。