3 回答

TA貢獻1911條經(jīng)驗 獲得超7個贊
let array = [];
//you can try with a email that doens't exist into the array
let email = 'prueba1@gmail.com'
//
let recipientData = {
name: 'prueba1',
email: 'prueba1@gmail.com',
};
array.push(recipientData)
recipientData = {
name: 'prueba2',
email: 'prueba2@gmail.com',
};
array.push(recipientData)
//im creating two new elemnts into the array
console.log(array)
//here we going to find the key of the element comparing the email
const index = array.findIndex(el => el.email === email);
if (index === -1) {
//if don't existe you can create a new one
console.log('dont exist')
}else{
// and if exist we removed, array.splice(), index, and we specific than removed exactly one
const removed = array.splice(index, 1)
//and return the element removed
console.log(removed)
}
// and console.log array to verify
console.log(array)
你好,我給你留下了一個例子和代碼的規(guī)范,我在代碼中留下了注釋。

TA貢獻1852條經(jīng)驗 獲得超1個贊
好的,完成了
$('#mail-recipient-table tbody').on('click', '.deleted', function () {
let value = $(this).closest('tr').find('td').eq(1).text();
for(let i = 0; i < recipientsArray.length; i++) {
if(recipientsArray[i].name == value) {
recipientsArray.splice(i, 1);
break;
}
}
console.log(recipientsArray);
dataTable
.row($(this).parents('tr'))
.remove()
.draw();
});

TA貢獻2051條經(jīng)驗 獲得超10個贊
$(document).ready(function () {
$('#example tbody tr').click(function () {
var index = $(this).closest("tr")[0];
oTable.fnDeleteRow(oTable.fnGetPosition(index));
});
var oTable = $('#example').dataTable();
});
添加回答
舉報