问题描述
我在一个datagridColumn中有这个奇怪的行为,我已经自定义它的单元格作为checkBox而不是dafault itemRenderer(即字符串)。相关代码如下: < mx:DataGridColumn sortable =falsetextAlign =centerheaderText = width =20dataField =colCB>
< mx:itemRenderer>
< mx:Component>
< mx:CheckBox selected =true>
< mx:Script>
<![CDATA [
import mx.controls.Alert;
public function change():void {
// TODO
}
]]>
< / mx:Script>
< / mx:CheckBox>
< / mx:Component>
< / mx:itemRenderer>
< / mx:DataGridColumn>
嗯,发生什么事情,每当我检查一个复选框,其他复选框(在其他行)得到随机选择或取消选中,如果我向下或向上滚动,则再次随机选择选择或取消选择。
可以有人帮我这个人吗?
谢谢提前
PS顺便一提,我已经压制了开始<在标签中,因为它弄乱了textEditor,但在我的代码中,他们在那里
我的猜测是这个问题不是复选框被随机检查并取消选中。 DataGrid
回收其 itemRenderers
以获得更好的内存性能。可能发生的情况是,您在 itemRenderer
上检查 CheckBox
,然后开始滚动, itemRenderer
与复选框正在重新使用以显示其他记录,而 selected =true
仍然设置。
我会做的是创建一个itemRenderer组件,并覆盖集数据
方法将复选框的选定值设置为应该是。 / p>
对于itemRenderer,我的头顶部的一些示例代码(您需要调整以供使用):
< mx:HBox horizontalScrollPolicy =offverticalScrollPolicy =off>
< fx:脚本>
<![CDATA [
覆盖公共函数集数据(value:Object)):void
{
super.data = value;
if(value [myCheckBoxData]!= null)
{
myCheckBox.selected = Boolean(value [myCheckBoxData]);
}
validateDisplayList();
}
]]>
< / fx:脚本>
< mx:CheckBox id =myCheckBox/>
< / mx:HBox>
I'm having this weird behaviour in a datagridColumn which I've customized to have its cells rendered as checkBoxes rather than the dafault itemRenderer (i.e. strings). The relevant code is as follows:
<mx:DataGridColumn sortable="false" textAlign="center" headerText="" width="20" dataField="colCB">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox selected="true">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function change():void{
//TODO
}
]]>
</mx:Script>
</mx:CheckBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
Well, what happens is that whenever I check a checkbox, other checkboxes (in other rows) get randomly checked or unchecked, and if I scroll down or up they once again randomly get selected or unselected.
Can anybody help me with this one?
Thanks is advance
PS by the way, I've suppressed the starting "<" in the tags because it was messing with the textEditor, but in my code they're there
My guess is that the issue isn't that the checkboxes are getting randomly checked and unchecked. The DataGrid
recycles its itemRenderers
for better memory performance. What's likely happening is that you're checking a CheckBox
on an itemRenderer
and start scrolling, that itemRenderer
with the checked box is getting reused to display other records with the selected="true
" value still set.
What I would do is create an itemRenderer component and override the set data
method to set the checkbox's selected value to what it should be.
Some sample code off the top of my head for the itemRenderer (you'll want to adjust it for your use):
<mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off">
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
{
super.data = value;
if (value["myCheckBoxData"] != null)
{
myCheckBox.selected = Boolean(value["myCheckBoxData"]);
}
validateDisplayList();
}
]]>
</fx:Script>
<mx:CheckBox id="myCheckBox" />
</mx:HBox>
这篇关于Flex DataGrid中的ItemRenderer的奇怪行为 - 复选框 - FLEX 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!