gpt4 book ai didi

javascript - 数据表中的乘法

转载 作者:行者123 更新时间:2023-11-30 15:52:56 25 4
gpt4 key购买 nike

所以我在下面有这段代码。

$(document).ready(function() {

function getCodeNameSpecsSize(data, type, dataToSet) {
return data[3] + ", " + data[4] + ", " + data[5] + ", " + data[6];
}

function getTotalPrice(data, type, dataToSet) {
return data[7] * data[9];
}

var table = $('#incoming_material').dataTable( {
"aProcessing": true,
"aServerSide": true,
"scrollY": 350,
"scrollX": true,
"deferRender": true,
"ajax": "Scripts/server-response-im.php",
"aoColumns": [
{"data": "1", "sClass": "align_center"},
{"data": "2", "sClass": "align_center"},
{"data": getCodeNameSpecsSize, "sClass": "align_center"},
{"data": "7", "sClass": "align_center"},
{"data": "8", "sClass": "align_center"},
{"data": "9", "sClass": "align_center"},
{"data": "10", "sClass": "align_center",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
var $currencyCell = $(nTd);
var commaValue = $currencyCell.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
$currencyCell.text(commaValue);
}
},
{"data": getTotalPrice, "sClass": "align_center",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
var $currencyCell = $(nTd);
var commaValue = $currencyCell.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
$currencyCell.text(commaValue);
}
},
{"data": "11", "sClass": "align_center"},
{ "mData": null , "sClass": "align_center",
"mRender" : function ( data, type, full ) {
return '<a href="redirect_preview_po.php?c='+data[2]+'" target=_blank>Preview</a>';}
}
],
"aaSorting": [[0,'desc']],
dom: 'Bfrtip',
lengthMenu: [
[ 10, 25, 50, -1 ],
[ '10 rows', '25 rows', '50 rows', 'Show all' ]
],
buttons: [
'pageLength',
'print',
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5',
'colvis'
],
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

我使 getCodeNameSpecsSize 函数起作用,但 getTotalPrice 函数不起作用。该表向我显示 NaN 值而不是 qty * unit_price。

QTY = data[7];
Unit Price = data[9];

提前致谢。任何帮助将不胜感激。

最佳答案

您可能想要检查数据[7] 和数据[9] 的类型。如果它们是字符串类型,则乘法可能不起作用。

尝试使用 parseInt(data[7]) * parseInt(data[9]) 看看是否有效。

关于javascript - 数据表中的乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39032134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com