第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從數(shù)據(jù)表中刪除數(shù)據(jù)推送數(shù)組(也許使用pop)(javascript)

如何從數(shù)據(jù)表中刪除數(shù)據(jù)推送數(shù)組(也許使用pop)(javascript)

慕蓋茨4494581 2023-07-06 15:05:21
我試圖通過我自己制作的數(shù)組消除數(shù)據(jù),在其中添加數(shù)據(jù),同時通過表給它們添加正如您所看到的,該添加按鈕會生成一個數(shù)組,每次單擊添加按鈕時,我都會使用 Push 來一一輸入每個數(shù)據(jù)我有另一個用于刪除按鈕的函數(shù),我可以在其中從表中刪除行,但顯然它不會在數(shù)組中執(zhí)行此操作我現(xiàn)在心里有兩件事:一種選擇是創(chuàng)建另一個已刪除數(shù)據(jù)數(shù)組,雖然我要同時保存,但已刪除數(shù)據(jù)數(shù)組中標(biāo)記的數(shù)據(jù)將被刪除我認為最好的另一個選擇是使用刪除按鈕通過相同的 JavaScript 來從我擁有的唯一數(shù)組中刪除數(shù)據(jù),我希望該按鈕只是從所選數(shù)組中刪除數(shù)據(jù),但我認為這使得我很難再多做一點什么以及我需要幫助什么這是我到目前為止添加的代碼$('#btn-add').on('click', function () {               let name = $('#name').val();                let email = $('#email').val();                let duplicated = checkDuplicate(email);                if ($('#digest-report-form').valid() && !duplicated) {                    addRow(itemCounter, name, email);                    itemCounter++;                    $('#name').val("");                    $("#email").val("");                   let recipientData = {                        name: name,                        email: email,                    };                    recipientsArray.push(recipientData);                  $('#recipients').val(JSON.stringify(recipientsArray));                    console.log($('#recipients').val());               } else if (duplicated) {                   $('#alert').show();                    setTimeout(function () {                        $('#alert').hide();                    }, 3000);                }            });這是刪除按鈕的功能代碼,目前不會對數(shù)組執(zhí)行任何操作$('#mail-recipient-table tbody').on('click', '.deleted', function () {                        dataTable                            .row($(this).parents('tr'))                            .remove()                            .draw();                    });我正在考慮使用 pop,但為此我必須對數(shù)組進行排序以將最后一個數(shù)組作為所選數(shù)組,這里的想法對我來說有點困難,感謝您的閱讀:)
查看完整描述

3 回答

?
Smart貓小萌

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ī)范,我在代碼中留下了注釋。



查看完整回答
反對 回復(fù) 2023-07-06
?
小怪獸愛吃肉

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();

            });


查看完整回答
反對 回復(fù) 2023-07-06
?
侃侃無極

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();

 });


查看完整回答
反對 回復(fù) 2023-07-06
  • 3 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號