我有一個功能,給了我一些數據輸出:如何拆分逗號分隔變量?
$(document).ready(function() {
var table = $('#myTable').DataTable();
table.MakeCellsEditable({
"onUpdate": myCallbackFunction
});
});
function myCallbackFunction(updatedCell, updatedRow, oldValue,row) {
console.log("The values for each cell in that row are: " + updatedRow.data());
}
我的控制檯輸出爲:The values for each cell in that row are: 2,Alan,Dirt,[email protected]
我現在想輸出我的函數裏面只有逗號分隔的列表的第一個值。所以,我把它改成如下:
function myCallbackFunction(updatedCell, updatedRow, oldValue,row) {
var row = updatedRow.data();
var id = row.split(",");
console.log("The first value is: " + id[0]);
}
但我得到的控制檯錯誤現在TypeError: row.split is not a function. (In 'row.split(",")', 'row.split' is undefined)
這是什麼意思?
哪個版本的jquery簡稱 –
@BalajiM的版本是2.2.3 – Jarla