javascript - 数据表数字转换为八进制
问题描述
在数据表中,我面临一个挑战
我有一些前导零(0461)的数字。数据在数据表中正确显示,但是当我单击该数字并传入一种方法时,它会转换为其他数字,可能是八进制数
例如 0461 转换为 86。
请提出一些建议
我的数据表代码是
var table = $('#example').DataTable({
processing : true,
serverSide : true,
pageLength : 10,
ajax : {
url : "/codes",
data : function(data) {
}
},
columns : [ {
"data" : "code",
"name" : "Code",
"title" : "Code",
"render" : function(data) {
// From here I am passing 0461
return '<a class="link" onclick="return searchCode('+data+');">' + data + '</a>';
}
} ],
columnDefs : [ {
"targets" : [ 1],
"searchable" : false
}, {
"targets" : [ 0],
"orderable" : true
} ]
});
// But here getting 86
function searchCode(code) {
console.log(code);
}
在数据表中的数据如下所示
解决方案
找到下面的解决方案
var table = $('#example').DataTable({
processing : true,
serverSide : true,
pageLength : 10,
ajax : {
url : "/codes",
data : function(data) {
}
},
columns : [ {
"data" : "code",
"name" : "Code",
"title" : "Code",
"render" : function(data) {
// From here passing this instead of data
return '<a class="link" onclick="return searchCode(this);">' + data + '</a>';
}
} ],
columnDefs : [ {
"targets" : [ 1],
"searchable" : false
}, {
"targets" : [ 0],
"orderable" : true
} ]
});
// It will print what we will pass from above method
function searchCode(code) {
console.log(code.text); // print 0461
}
推荐阅读
- google-chrome-extension - 注入的脚本未加载
- java - Jackson JSON 转换舍入整数范围以外的值 (2^32)
- css - 如何在 css 类中与其他元素分开选择一堆元素?
- c# - Moq + Autofixture:对依赖属性使用设置会清除整个模拟对象
- javascript - 不使用边框的圆形边框-?
- python - 如何从一个简单的数学方程的结果中创建一个列表?
- pandas - 用 .loc 替换值
- c# - 如何在 LINQ to SQL 中编写右侧为空的 LEFT OUTER JOIN?
- snowflake-cloud-data-platform - 雪花:过滤包含正确日期值的行
- mysql - Mysql外键约束删除