在 Flex3 中显示列表 ItemRenderer 索引 [英] Display List ItemRenderer Index in Flex3

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

问题描述

是否有直接的方法可以获取 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.

推荐答案

第一个答案似乎有效,但速度很慢.每次运行 dataProvider 数组以获取项目索引需要 O(n^2) 时间.我们可以从 listData 访问 rowIndex - 它代表当前可见项的索引.来自父 List 的垂直滚动位置表示滚动项的数量:

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>

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

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