3 回答
TA贡献1911条经验 获得超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)
你好,我给你留下了一个例子和代码的规范,我在代码中留下了注释。
TA贡献1852条经验 获得超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条经验 获得超10个赞
$(document).ready(function () {
$('#example tbody tr').click(function () {
var index = $(this).closest("tr")[0];
oTable.fnDeleteRow(oTable.fnGetPosition(index));
});
var oTable = $('#example').dataTable();
});
添加回答
举报