Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash Flex<;s:列表>;Itemrender索引_Flash_Apache Flex_Indexing_Adobe_Itemrenderer - Fatal编程技术网

Flash Flex<;s:列表>;Itemrender索引

Flash Flex<;s:列表>;Itemrender索引,flash,apache-flex,indexing,adobe,itemrenderer,Flash,Apache Flex,Indexing,Adobe,Itemrenderer,Flex(4.6)中的项目呈现器中是否有方法在项目呈现器本身中标识列表中特定项目的索引 我尝试使用类的itemIndex属性,但它总是返回零。另外,给了我几个运行时错误 谢谢您的时间。主要应用程序: <?xml version="1.0" encoding="utf-8"?> <s:Application width="100%" height="100%" xmlns:fx="http://ns.adobe.com/mxml/2009" xm

Flex(4.6)中的
项目呈现器中是否有方法在项目呈现器本身中标识列表中特定项目的索引

我尝试使用类的
itemIndex
属性,但它总是返回零。另外,给了我几个运行时错误

谢谢您的时间。

主要应用程序:

<?xml version="1.0" encoding="utf-8"?>
<s:Application
    width="100%"
    height="100%"
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:List itemRenderer="IndexedItemRenderer">
        <s:dataProvider>
            <s:ArrayList>
                <fx:String>Item A</fx:String>
                <fx:String>Item B</fx:String>
                <fx:String>Item C</fx:String>
                <fx:String>Item D</fx:String>
                <fx:String>Item E</fx:String>
            </s:ArrayList>
        </s:dataProvider>
    </s:List>
</s:Application>

项目A
B项
项目C
项目D
项目E
IndexedItemRenderer项目呈现器:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    autoDrawBackground="true">
    <s:Label text="{itemIndex + 1}. {data}"/>
</s:ItemRenderer>

我刚刚注意到,
itemIndex
不起作用,因为它的值在列表创建的生命周期中尚未设置

在项目呈现器中,我正在侦听一个
AddedStatage
事件,并在其处理程序中使用了
itemIndex
。一旦我将
AddedStatage
事件更改为
creationComplete
itemIndex
则具有正确的值


希望这对其他人有所帮助。

谢谢您的评论!我刚刚弄明白为什么
itemIndex
没有返回正确的值。我在上面发布了我的答案。如果可行,请在项目渲染器中使用数据绑定。与第一次尝试相比,我刚刚更新了我的项目渲染器,使用您提到的itemIndex是一个更好的选项。我将使用数据绑定,但索引用于对列表中的每个项目执行的计算。