自定义外部 itemRenderer 正在从 dataProvider 接收空对象

Custom external itemRenderer is receiving null objects from dataProvider

我有一个自定义的外部 itemRenderer,我用它来显示 mx:List 中的项目。 dataProvider 是一个数组,每个元素包含 4 个属性。似乎 itemRenderer 实际上正在获取数组,因为它显示 4 个项目(数组中项目的数量),但这些项目显示为“[object Object]”。

这是我的 itemRenderer...

<mx:Metadata>
    [Event(type="classes.events.RemoveEntryEvent", name="removeProject")]
</mx:Metadata>

<mx:Script>
    <![CDATA[
        import classes.events.RemoveEntryEvent;

        import mx.controls.Alert;
        import mx.events.CloseEvent;
        import mx.events.FlexEvent;

        override public function set data (value:Object):void{
            super.data = value;
            //Alert.show(value.toString());
        }

         public function button_clickHandler():void {
            var alertListener:Function = function(closeEvent:CloseEvent):void{
                if (closeEvent.detail == Alert.YES){
                    //dispatchEvent(new RemoveEntryEvent(RemoveEntryEvent.REMOVE_PROJECT, true, false, data));
                }
            } 

            var myAlert:Alert = Alert.show("Are you sure you want to remove yourself from this project?", 
                "Remove Project", 
                (Alert.YES | Alert.CANCEL),
                null, alertListener);

            myAlert;
        }      

        private function text_clickHandler():void{
            Alert.show("inside text_clickHandler()");
        }



    ]]>
</mx:Script>

<!-- The mx:Text should display a hand maybe when rolledOver: !buttonMode, -->
<mx:Text id="text" width="85%" text="{data}" fontThickness="5" click="text_clickHandler()"/>
<mx:Button id="removeButton" label="Remove" fontSize="9" width="63" verticalCenter="0" fontWeight="normal" x="329" 
           height="17" click="button_clickHandler()"></mx:Button>


</mx:Canvas>

当我逐步执行设置数据功能时,'value:Object' 为空!但同样,它显示了正确数量的项目。

这是我的 mxml 代码,其中包含我的 mx:List...

<mx:TitleWindow y="10" width="550" height="342" layout="absolute" title="LIST OF PROJECTS" cornerRadius="4" id="listOfProjects_panel" horizontalCenter="0"> 
    <mx:List alternatingItemColors="{altColors}" x="65.5" y="30" width="399" height="232" backgroundColor="#F8F8F8" fontSize="12" dataProvider="{xmlSimpleArray}"
                             id="list_of_projects_master" initialize="listInitializer()" useRollOver="false" selectable="false">
    </mx:List>
    <mx:Button y="270" label="Refresh List" width="130" x="334.5" id="auth_btn_master0" fontWeight="normal"/>
    <mx:Label x="65.5" y="10" text="Click To Select A Project:" fontWeight="bold"/>
</mx:TitleWindow>

这是我 mx:Script...

中的初始化程序
private function listInitializer():void{
            //list_of_projects_master.dataProvider = xmlSimpleArray;
            list_of_projects_master.itemRenderer = new ClassFactory(ProjectListRenderer);
            list_of_projects_master.addEventListener(RemoveEntryEvent.REMOVE_PROJECT, updateXML);
        }

如果需要更多信息来评估问题,请告诉我

更改 itemrenderer 中的以下行

<mx:Text id="text" width="85%" text="{data}" fontThickness="5" click="text_clickHandler()"/>

应该是

<mx:Text id="text" width="85%" text="{data.labelfieldname}" fontThickness="5" click="text_clickHandler()"/>

希望对您有所帮助。