Flex4 DataGrid ItemRenderer内嵌方式

Flex4 DataGrid ItemRenderer像Flex3一直内嵌ItemRenderer会报空对象引用的错误,如:

<s:GridColumn dataField="title" headerText="Label">
    <s:itemRenderer>
        <fx:Component>
            <s:Image source="assets/img/1.jpg" width="110" height="110"/>
        </fx:Component>
    </s:itemRenderer>
</s:GridColumn>

需要添加GridItemRenderer

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="application1_creationCompleteHandler()">
    <s:layout>
        <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
            [Bindable]
            private var ac:ArrayCollection = new ArrayCollection([
                {img:'1.jpg',name:'黄家驹',record:'再见理想'},
                {img:'2.jpg',name:'BEYOND',record:'海阔天空'}
            ]);        
        ]]>
    </fx:Script>
    <s:DataGrid id="gridImage" width="402" height="600" dataProvider="{ac}">
        <s:columns>
            <s:ArrayList>
                <s:GridColumn dataField="img" headerText="ID" width="110">
                    <s:itemRenderer>
                        <fx:Component>
                            <s:GridItemRenderer>
                                <s:Image source="assets/img/{data.img}" width="110" height="110"/>
                            </s:GridItemRenderer>
                        </fx:Component>
                    </s:itemRenderer>
                </s:GridColumn>
                <s:GridColumn dataField="name" headerText="姓名" width="90"></s:GridColumn>
                <s:GridColumn dataField="record" headerText="专辑" width="200"></s:GridColumn>
            </s:ArrayList>
        </s:columns>
    </s:DataGrid>
</s:Application>

 

posted @ 2013-08-09 12:21  牧之丨  阅读(2805)  评论(0编辑  收藏  举报