简体   繁体   English

在Flex中访问项目渲染器的属性

[英]Access a property of an item renderer in Flex

I have a datagrid with a combobox in it like; 我有一个数据网格,里面有一个组合框。

   <mx:DataGrid editable="true"  x="72" y="10" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getAllResult.lastResult}" height="178" width="896">
        <mx:columns>
            <mx:DataGridColumn headerText="STATUS" dataField="tooltip"/>
            <mx:DataGridColumn headerText="CUSTOM" editable="false" width="250" labelFunction="meAdnan"  >
                <mx:itemRenderer>
                    <fx:Component className="myEditor2">
                        <mx:VBox height="100%" >
                            <mx:ComboBox  id="pickState" labelField="attname" 
                                          dataProvider="{parentApplication.getAllResult2.lastResult}" 
                                         >
                            </mx:ComboBox>

                        </mx:VBox>
                    </fx:Component>                 
                </mx:itemRenderer>
            </mx:DataGridColumn>
        </mx:columns>
   </mx:DataGrid>

Now when I want to access a function from the itemrendered/combobox i use parentApplication.funcName but what about accessing the other way, how can I access a property of the combobox from outside the itemrenderer? 现在,当我想从itemrendered / combobox访问函数时,我使用parentApplication.funcName但是以另一种方式访问​​又如何,如何从itemrenderer外部访问combobox的属性呢? I tried myEditor2.pickState but it is now working 我尝试了myEditor2.pickState但是现在可以正常工作了

parentApplication will refer to the main Application class which may not always be what you intend to access - what if your DataGrid is in a component that extends Canvas . parentApplication将引用主Application类,而该类可能并不总是您要访问的主类-如果您的DataGrid位于扩展Canvas的组件中,该怎么办。 Use outerDocument to access the owning document from an itemRenderer . 使用outerDocumentitemRenderer访问拥有的文档。 So it should be outerDocument.funcName . 因此它应该是outerDocument.funcName

Accessing itemRenderer instances directly is not a good idea as item renderers are reused when you scroll the list etc. So if you get a reference to the renderer instance of the first row and you scroll down the list a bit, that same instance (which you believe to be the first row) might now represent the 3rd or 5th (or whatever) row depending on how many rows you scrolled. 直接访问itemRenderer实例不是一个好主意,因为在滚动列表等时将重用项目渲染器。因此,如果获得对第一行的渲染器实例的引用,然后向下滚动列表,则该实例(相信是第一行)现在可以代表第三行或第五行(或其他任何行),具体取决于您滚动了多少行。 The correct way is to override the public set data method and manipulate it from there based on the data. 正确的方法是重写public set data方法,并根据数据从那里进行操作。

That said, you can use indexToItemRenderer method to get a reference to the current item renderer at a given index. 也就是说,您可以使用indexToItemRenderer方法获取给定索引处对当前项目渲染器的引用。 Cast it to the correct type (or assign it to a variable typed as Object ) and read its pickState property. 将其强制转换为正确的类型(或将其分配给类型为Object的变量)并读取其pickState属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM