【发布时间】:2017-08-11 20:14:16
【问题描述】:
我曾经使用 PHP 来打印我的数据表。当我到达一个字符串大于 17 个字符的特定列时,我将使用以下内容在第 17 个字符之后打印省略号:
if(strlen($row[tli]) > 17){echo "<td><a href='#'>".substr(row['number'],0,17)."..."</a></td>";}
我需要使用 ajax 来做同样的事情。
$('#example1').DataTable({
"ajax": {
"url": "api/displayQnams.php",
"type": "POST",
"dataSrc": ''
},
"columns": [
{
"data": "number",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol)
{
if(oData.number.length > 17) // here is where the initial check starts
{$(nTd).html("<a href='#'>'"+oData.number+"...'</a>")} // here is where it should print the ellipses after the 17th character
else
{$(nTd).html("<a href='#'>'"+oData.number+"'</a>"}
}
}
]
});
oData.number.length 在控制台中给我以下错误:
Cannot read property 'length' of undefined
我缺少什么来完成这项工作?
【问题讨论】:
标签: javascript jquery json ajax datatables