显示列表的ItemRenderer指数FLEX3指数、列表、ItemRenderer

2023-09-08 13:49:14 作者:/.赱私娚孒o.

有没有一种直接的方式进去的itemRenderer的数据项指数?我需要显示对每个项目的项目编号。我目前在做一个解决办法,不会让我的itemRenderer组件的重用。

Is there a direct way to get the item index of the data inside an itemRenderer? I need to display the item number against each item. I am currently doing a workaround and won't allow reuse of my itemRenderer component.

var index:int = model.dataColl.getItemIndex(data) + 1;
itemNo = index.toString();

这是我现在使用的,它的工作原理,但组件的重用和数据抽象的概念受到损害。

This is what i am using now, it works, but the concepts of component reuse and data abstraction are compromised.

我使用的Flex 3。

I am using Flex 3.

推荐答案

第一个答案似乎是工作,但速度缓慢。这需要为O(n ^ 2)时间,因为它贯穿dataProvider Array中每次都得到项目索引。 我们可以从的ListData访问rowIndex位置 - 它重新presents目前可见项目的索引。从父目录重$ P $垂直滚动位置psents滚动项目金额:

The first answer seems to be working, but slow. It takes O(n^2) time as it runs through dataProvider array to get item index each time. We can access rowIndex from listData - it represents index of the current visible item. Vertical scroll position from parent List represents the amount of scrolled items:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.controls.listClasses.IDropInListItemRenderer">
<mx:Script>
    <![CDATA[
        import mx.controls.listClasses.BaseListData;
        import mx.controls.listClasses.ListBase;

        [Bindable] private var index:int = 0;

        private var _listData:BaseListData;
        public function get listData():BaseListData
        {
            return _listData;
        }
        public function set listData(value:BaseListData):void
        {
            _listData = value;
        }

        override public function set data(value:Object):void
        {
            super.data = value;
            if (data && listData)
                index = _listData.rowIndex + ListBase(_listData.owner).verticalScrollPosition;
            else
                index = 0;
        }
    ]]>
</mx:Script>
<mx:Label text="{index}"/>
<mx:Label text="{data.toString()}"/>
</mx:HBox>
 
精彩推荐
图片推荐