Calculate the index number of the row and column where the item is located according to the index value

  

getRowColIndex(itemIndex = 0, colCount = 3) {
    //必选参数:itemIndex是当前元素的索引值,从0开始计算(如果是从1开始,则需将传入值-1,即itemIndex--)
    //必选参数:colCount是每一行显示多少个元素
    return {
        colIndex: itemIndex % colCount,//计算列索引(从0开始)
        rowIndex: Math.floor(itemIndex / colCount),//计算行索引(从0开始)        
    }
},

Guess you like

Origin blog.csdn.net/qq_37860634/article/details/131939225