如何在 ItemRenderer 内使用数据网格范围外的变量?
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
someComponentVariable
是包含DataGrid
的类的公共属性,则可以使用outerDocument
从组件
访问它。请参阅 中的“使用组件标记”部分创建内联项渲染器和编辑器,了解有关
outerDocument
的更多信息If
someComponentVariable
is a public property of the class enclosingDataGrid
, you can useouterDocument
to access it from acomponent
.See the "using the Component tag" section in Creating inline item renderers and editors for more info about
outerDocument
不,你根本不能使用它。数据网格中的每个 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.