Например, тестирование 4 имеет уровень 1, а тестирование 1 имеет уровень 1. Они будут
объединены в один массив, потому что они имеют один и тот же уровень
То же самое и с остальными. Ниже я предоставил свои коды и скриншот моей цели. Любая помощь будет оценена по достоинству. Большое спасибо.

ajax fetch:
let ajaxResult = []; // the pushed data will be saved here
let table;
let base_url = "";
let result = [];
const combine = (source) => {
return source[0].data.reduce((acc, curr) => {
const [entryID, entryName, level] = curr;
if (acc[level])
acc[level].push({
entryID,
entryName,
level
});
else
acc[level] = [{
entryID,
entryName,
level
}];
return acc;
}, {})
}
$(document).ready(function() {
//datatables
table = $("#entry_list1").DataTable({
processing: false,
serverSide: true,
order: [],
searching: false,
paging: false,
info: false,
ajax: {
url: "",
type: "POST",
async: true,
dataType: "json",
success: function(data) {
ajaxResult.push(data); // I'm pushing my data to my ajaxResult variable
result = combine(ajaxResult); // Cleanup your data here.
console.log(combine(ajaxResult)); // The result in image i provided above is from here.
},
},
"columnDefs": [{
"targets": [0], //first column
"orderable": false, //set not orderable
},
{
"targets": [-1], //last column
"orderable": false, //set not orderable
},
],
});
});
вставка ajax:
// i want to pass my ajaxResult = []; here so that i can insert it into my database
$("#insertMe").submit(function(event) {
var form = $('#insertMe')[0];
var formData = new FormData(form);
event.preventDefault();
$.ajax({
url: "",
cache: false,
contentType: false,
processData: false,
data: formData,
type: "post",
async: false,
dataType: 'json',
success: function(data){
},
});
});
контроллер:
function inserFunction() {
$this->db->insert('matching', $data);
}
Подробнее здесь: https://stackoverflow.com/questions/680 ... t-it-in-db
Мобильная версия