美文网首页
2021-08-06 切割长数组

2021-08-06 切割长数组

作者: 0说 | 来源:发表于2021-08-06 16:29 被阅读0次
    function ajaxSplit(arr) {
        return new Promise(async (resolve, reject) => {
            const chunks = [];
            let results = [];
            for (let i = 0; i < arr.length;) {
                const end = i + 10;
                chunks.push(arr.slice(i, end))
                i = end
            }
            console.log(chunks)
            try {
                for (let i = 0; i < chunks.length; i++) {
                    console.log(chunks[i].map(v => v()))
                }
                resolve(results)
            } catch (error) {
                console.log(error)
                resolve(results)
            }
    
        });
    }
    

    调用方法

    let arr = [
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                },
                {
                    name: '小红',
                    age: 10
                }
            ]
            let a = function(a, b) {
                return a + b
            }
            ajaxSplit(
                arr.map(item => {
                    return () => {
                        return a(item.name, item.age)
                    }
                })
            )
    

    长数组分页

    <el-table
            :data="currentPageData"
            style="width: 100%"
            :header-cell-style="{ color: '#4CD7FE', background: '#0D4071' }"
            :row-class-name="tableRowClassName"
            height="calc(100% - 0px)"
          >
          </el-table>
          <pagination
            ref="pagination"
            :total="allDevices.length"
            @handlePageParamsChange="handlePageParamsChange"
          />
    <script>
    export default {
      data() {
        return {
          params: {
            currentPage: 1,
            size: 15,
          },
        };
      },
      computed: {
        currentPageData() {
          const { currentPage, size } = this.params;
          return [长数组].slice((currentPage - 1) * size, currentPage * size );
        },
       
      },
      methods: {
        handlePageParamsChange(params) {
          this.params = params;
        },
      },
    };
    </script>
    

    相关文章

      网友评论

          本文标题:2021-08-06 切割长数组

          本文链接:https://www.haomeiwen.com/subject/nvfivltx.html