显示列表的ItemRenderer指数FLEX3 [英] Display List ItemRenderer Index in Flex3

查看:124
本文介绍了显示列表的ItemRenderer指数FLEX3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种直接的方式进去的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>

这篇关于显示列表的ItemRenderer指数FLEX3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆