如何在 ItemRenderer 中使用超出数据网格范围的变量?

问题描述:

我正在使用 ItemRenderer 将一组项目绑定到数据网格.我使用 data 变量来控制可绑定数据.我还有 someComponentVariable 需要插入每一行,但它在组件范围内声明,所以数据网格似乎没有重新调整它(编译错误).

I'm binding an array of items to a data grid using ItemRenderer. I use the data variable to control the bindable data. I also have someComponentVariable that need be inserted into every row but its declared at the component scope, so the data grid doesn't seem to reconize it (compile error).

如何在 ItemRenderer 中使用这个变量 (someComponentVariable)?

How can I use this variable (someComponentVariable) inside the ItemRenderer?

<mx:DataGrid id="userBonusesGrid" width="100" height="248" showHeaders="false" wordWrap="true">
    <mx:columns>
        <mx:DataGridColumn headerText="" width="36">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox verticalAlign="middle" horizontalAlign="center">
                        <ns1:SidePanelBonus 
                            bonusName="{data.name}" description="{data.description}" 
                            arrow="{someComponentVariable}">
                        </ns1:SidePanelBonus>   
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

如果 someComponentVariable 是包含 DataGrid 的类的公共属性,则可以使用 outerDocumentcomponent 访问它.

If someComponentVariable is a public property of the class enclosing DataGrid, you can use outerDocument to access it from a component.

<ns1:SidePanelBonus bonusName="{data.name}" description="{data.description}" 
    arrow="{outerDocument.someComponentVariable}">
</ns1:SidePanelBonus>   

请参阅 创建内联项目渲染器和编辑器 以了解有关 outerDocument

See the "using the Component tag" section in Creating inline item renderers and editors for more info about outerDocument