当前位置: 动力学知识库 > 问答 > 编程问答 >

flex - TileList item location

问题描述:

In a flex tileList, is there a way to get the cell-address of a given item? i.e. for a given item, get the row/column location for that item in the list.

网友答案:

I've checked the documentation, and no directly, but with a bit of arithmetic you can get yourself sorted.

//asumming this is a change handler
function myTileListChanged(event:Event):void{
    var itemsPerRow:Number = myTileList.dataProvider.length / myTileList.rowCount;
    var selectedRow:int = Math.floor(myTileList.selectedIndex / itemsPerRow);
    var selectedColumn:int = myTileList.selectedIndex - (itemsPerRow * selectedRow);
    trace('index: ' + myTileList.selectedIndex + ' is at row: ' + selectedRow + ' column: ' + selectedColumn);
}

Note, I've used the TileList in Flash, so dataProvider might be slightly different, but you'll still be able to get the picture. HTH!

分享给朋友:
您可能感兴趣的文章:
随机阅读: