如何在 ItemRenderer 内使用数据网格范围外的变量?

发布于 2024-08-05 05:49:45 字数 1074 浏览 2 评论 0原文

我使用 ItemRenderer 将项目数组绑定到数据网格。我使用 data 变量来控制可绑定数据。我还有 someComponentVariable 需要插入到每一行中,但它是在组件范围内声明的,因此数据网格似乎无法重新识别它(编译错误)。

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

代码示例

<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>

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).

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

Code Example

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灼疼热情 2024-08-12 05:49:45

如果 someComponentVariable 是包含 DataGrid 的类的公共属性,则可以使用 outerDocument组件 访问它。

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

请参阅 中的“使用组件标记”部分创建内联项渲染器和编辑器,了解有关 outerDocument 的更多信息

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>   

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

兮子 2024-08-12 05:49:45

不,你根本不能使用它。数据网格中的每个 itemRenderer 只能访问为其创建渲染器的项目。这是故意这样做的,因为 itemRendrers 动态变化,它们不会永远绑定数据,当您滚动时,项目会滚动而不是渲染器,它们保持在相同位置或者可能会发生变化,但是当您滚动时相应项目渲染器的数据总是会变化。他们不具有一对一的关系。

唯一的解决方案是以某种父子关系的形式传递项目中的数据。

No you can not use it at all. Each itemRenderer in data grid can only access the item for which the renderer was created. And this is done purposely because itemRendrers change dynamically, they are not bound for data forever, when you scroll, the items get scrolled not the renderers, they remain in same position or they might change, but corresponding item renderer's data always changes when you scroll. They dont share one to one relationship.

The only solution is to pass the data in the item in the form of some parent child relationship.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文