This is my application:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import spark.components.gridClasses.IGridItemRenderer;
public var modulesXMLList:XMLListCollection;
private function onGridInitialize(event:FlexEvent):void{
this.addEventListener('moduleItemChange', onModuleItemChange);
}
private function onModuleItemChange(event:Event):void{
var item:IGridItemRenderer = event.target as IGridItemRenderer;
if(!item || !item.data)
//item.data.access = !item.data.access;
Alert.show(item.data.sub_module);
}
protected function controlPanel_Datagrid_creationCompleteHandler(event:FlexEvent):void
{
modulesXMLList = new XMLListCollection(tempXML.module as XMLList);
modulesXMLList.refresh();
myDatagrid.dataProvider = modulesXMLList;
}
]]>
</fx:Script>
<fx:Declarations>
<s:RadioButtonGroup id="rbg1"/>
<fx:XML id="tempXML" source="assets/myXMl1.xml"/>
<!--<s:ArrayCollection id="moduleControlPanel_DP">
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub1" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub2" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub3" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub4" default="true" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub5" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub6" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub7" default="true" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub8" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub9" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub11" default="true" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub11" default="true" access="true"/>
</s:ArrayCollection>
-->
</fx:Declarations>
<s:DataGrid id="myDatagrid" creationComplete="controlPanel_Datagrid_creationCompleteHandler(event)" rowHeight="35" fontSize="9"
x="20" y="20" width="184" height="176">
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Default">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:RadioButton name="yoyo" group="{outerDocument.rbg1}" selected="@{data.default}" label="" horizontalCenter="0"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn headerText="Access" dataField="@access">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
{
// not sure of the details on when or why, but sometimes this method is passed a null value
if(value != null)
{
//super.data = value;
// set itemRenderer's state based on data value
//chk.selected = value.access;
super.data = value;
validateNow();
}
}
protected function Check_clickHandler(even:MouseEvent):void
{
dispatchEvent(new Event('moduleItemChange', true));
}
]]>
</fx:Script>
<s:CheckBox id="chk" click="Check_clickHandler(event)" label="" selected="@{data.access}" horizontalCenter="0"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn headerText="Sub-Module" dataField="@sub_module" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:Application>
And this my C<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import spark.components.gridClasses.IGridItemRenderer;
public var modulesXMLList:XMLListCollection;
private function onGridInitialize(event:FlexEvent):void{
this.addEventListener('moduleItemChange', onModuleItemChange);
}
private function onModuleItemChange(event:Event):void{
var item:IGridItemRenderer = event.target as IGridItemRenderer;
if(!item || !item.data)
//item.data.access = !item.data.access;
Alert.show(item.data.sub_module);
}
protected function controlPanel_Datagrid_creationCompleteHandler(event:FlexEvent):void
{
modulesXMLList = new XMLListCollection(tempXML.module as XMLList);
modulesXMLList.refresh();
myDatagrid.dataProvider = modulesXMLList;
}
]]>
</fx:Script>
<fx:Declarations>
<s:RadioButtonGroup id="rbg1"/>
<fx:XML id="tempXML" source="assets/myXMl1.xml"/>
<!--<s:ArrayCollection id="moduleControlPanel_DP">
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub1" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub2" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub3" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub4" default="true" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub5" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub6" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub7" default="true" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub8" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub9" default="false" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub11" default="true" access="true"/>
<fx:Object habilitations_id ="1" module_id="4" sub_module="Sub11" default="true" access="true"/>
</s:ArrayCollection>
-->
</fx:Declarations>
<s:DataGrid id="myDatagrid" creationComplete="controlPanel_Datagrid_creationCompleteHandler(event)" rowHeight="35" fontSize="9"
x="20" y="20" width="184" height="176">
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Default">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:RadioButton name="yoyo" group="{outerDocument.rbg1}" selected="@{data.default}" label="" horizontalCenter="0"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn headerText="Access" dataField="@access">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
{
// not sure of the details on when or why, but sometimes this method is passed a null value
if(value != null)
{
//super.data = value;
// set itemRenderer's state based on data value
//chk.selected = value.access;
super.data = value;
validateNow();
}
}
protected function Check_clickHandler(even:MouseEvent):void
{
dispatchEvent(new Event('moduleItemChange', true));
}
]]>
</fx:Script>
<s:CheckBox id="chk" click="Check_clickHandler(event)" label="" selected="@{data.access}" horizontalCenter="0"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn headerText="Sub-Module" dataField="@sub_module" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:Application>
And this is my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<modules>
<module habilitation_id="1" module_id="1" sub_module="Sub1" default="true" access="true" />
<module habilitation_id="1" module_id="2" sub_module="Sub2" default="true" access="true" />
<module habilitation_id="1" module_id="2" sub_module="Sub3" default="false" access="false" />
<module habilitation_id="1" module_id="2" sub_module="Sub4" default="false" access="true" />
<module habilitation_id="1" module_id="3" sub_module="Sub5" default="true" access="true" />
<module habilitation_id="1" module_id="3" sub_module="Sub6" default="false" access="true" />
<module habilitation_id="1" module_id="4" sub_module="Sub7" default="true" access="true" />
<module habilitation_id="1" module_id="4" sub_module="Sub8" default="false" access="true" />
</modules>
Anyone please throw some lights.
0
A
回答
0
這是一個有趣的。我遇到了一陣子。您的項目渲染器會在屏幕上滾動時被銷燬並重新使用。因此它看起來沒有被選中。如果我沒有記錯,試着將你的控件綁定到渲染器中的一個方法,該方法將它們的值更新爲數據對象中的值。例如<s:checkbox selected={myMethod(data.selected)} />
或在呈現器上查找更新事件並設置您的值。
0
剛看到這個帖子,似乎你還沒有接受還沒有任何答案:
你的項目渲染:
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
//chk.selected = value.access;
validateNow();
}
}
取消對上述行://chk.selected = value.access;
Flex DataGrid回收其itemRenderer以獲得更好的內存性能。當您檢查itemRenderer上的複選框並開始滾動時,帶有複選框的itemRenderer將被重用以顯示仍然設置了selected =「true」值的其他記錄。
所以你必須明確地設置複選框的值。對於這個例子,如果value.access是布爾值,並且它用於複選框,它肯定會工作。
謝謝。
相關問題
- 1. 當CheckBox被選中時Hilight表數據,未被選中時不被取消
- 2. ListVIew中的CheckBox使用SimpleCursorAdapter在滾動時被隨機選中
- 3. 在取消選擇並向下滾動後,listview中的複選框被選中。
- 4. 當我滾動瀏覽時,List中的複選框隨機獲取選中/取消選中。 android 2.3
- 5. 取消選中當另一個複選框被選中
- 6. CheckBox值內的文本框,當我輸入文本框時取消選中取消選中
- 7. 如何檢查和取消選中CheckBox?
- 8. 反應檢查和取消選中CheckBox
- 9. 我如何知道CheckBox被選中?
- 10. Checkedtextview check /取消選中後滾動Listview
- 11. 當第一個checkBox列被選中時獲取兩個DataGridViewCheckBoxColumn
- 12. 的CheckBox將自動取消選中時ExpandableListView擴大
- 13. jQuery的:當複選框被選中/取消更改下拉列表中選擇
- 14. 在Flex中,我該如何創建一個無法取消選中的CheckBox?
- 15. 複選框在滾動時在recyclerView中未被選中
- 16. 當取消選中複選框時,取消選中標題複選框
- 17. 當我取消選中複選框下一個複選框滾動ListView後得到選擇
- 18. 當複選框被選中/取消選中時如何隱藏/顯示內容?
- 19. 當表格行被點擊時選中和取消選中複選框
- 20. Cakephp:當複選框被選中/取消選中時啓用/禁用文本框
- 21. 爲什麼我的複選框總是被取消選中?
- 22. getJSON如果複選框被選中然後取消選中
- 23. 當checkBox被選中時更改輸入字段的內容
- 24. 當其中一個複選框選項被選中時,取消選中複選框
- 25. 如何在CheckBox被選中時獲取ListView ID?
- 26. 在Checkbox上執行命令。檢查或取消選中
- 27. 如何在android中限制超過時取消勾選CheckBox?
- 28. 當CheckBox被勾選時激活ComboBox
- 29. UIView backgroundColor當UITableViewCell被選中時消失
- 30. 當複選框被選中
有趣我知道...這就是我從昨天開始用這個拉頭髮 我嘗試在itemrenderer中使用set data方法,但它忽略它。我也嘗試使用validateNow()作爲一些例子,但徒勞無功。 – FlexyBoz
其他人請幫助這個..對我的項目非常緊迫..很多謝謝 – FlexyBoz