如何一次仅加载数组的5个元素并将其附加到前一个

我在获取数组元素并将它们一次附加5时遇到麻烦。

       retrieveAccounts() {
        if (accounts.body && accounts.body.serviceAccounts) {
            this.fields = accounts.body.serviceAccounts; // array that returns all accounts 
        } 
        this.accountLimit = this.accountLimit + 5 ; // counter 
        this.tempData = this.fields.splice(0,this.accountLimit);  
// returns first 5 accounts, how do I get the next five and append it to the first five and so on.
    }

// on load more, show the next five 
    loadMoreData(){
        if (this.showLoadMore){
            this.accountLimit += 5;
        }
    }

   get showLoadMore(){
        if (this.fields.length >= this.tempData){
            return false;
        } else {
            const currentData = this.fields;
            //Appends new data to the end of the table
            const newData = currentData.concat(this.tempData);
            this.fields = newData;
            return true;
        }
    }

我试图首先显示前5个元素,如果有更多元素,则获取下5个元素并将其附加到前5个元素中,如此。

评论