我在flex中创建了嵌套复选框。
我只想选择一个父复选框。 如果我选择父复选框(Cluster1),则应选中该父复选框的所有子复选框,并且在取消选中当前复选框之前不应单击其他父复选框。
复选框树的当前XML结构:
public var treeData:XML = <item name="vCenter Server" type="Server">
<item name = "Datacenter" type="Datacenter" checked="false">
<item name="Cluster1" type="ClusterComputeResource" id="mycusterOne" checked="false">
<item name = "Host 1" type="HostSystem" checked="false"/>
<item name = "Host 2" type="HostSystem" checked="false"/></item>
<item name="Cluster2" type="ClusterComputeResource" id="mycusterTwo" checked="false">
<item name = "Host 1" type="HostSystem" checked="false"/>
<item name = "Host 2" type="HostSystem" checked="false"/></item></item>
<item name = "Host 3" type="HostSystem" checked="false"> </item></item>;
和代码:
protected function chk_clickHandler(event:MouseEvent):void
{
var myListData:TreeListData = TreeListData(this.listData);
var selectedNode:Object = myListData.item;
var tree:Tree = Tree(myListData.owner);
var toggle:Boolean = chk.selected;
if(this.chk.selected){
//this.checked = true;
this.itemXml.@checked = "true";
}
else
{
//this.checked = false;
this.itemXml.@checked = "false";
}
var toggle:Boolean = chk.selected;
if (toggle)
{
toggleChildren(data, tree, "true");
}
else
{
toggleChildren(data, tree, "false");
if( this.itemXml.@type == "HostSystem" ){
toggleParents(data, tree, "false");
}
}
}
private function toggleChildren (item:Object, tree:Tree, checked:String):void
{
if (item == null) {
return;
} else {
if(item.@type == 'HostSystem') {
item.@checked = checked;
}
var treeData:ITreeDataDescriptor = tree.dataDescriptor;
if (treeData.hasChildren(item)) {
var children:ICollectionView = treeData.getChildren (item);
var cursor:IViewCursor = children.createCursor();
while (!cursor.afterLast) {
toggleChildren(cursor.current, tree, checked);
cursor.moveNext();
}
}
}
}
private function toggleParents (item:Object, tree:Tree, checked:String):void
{
if (item == null)
{
return;
}
else
{
if(item.@type == 'ClusterComputeResource')
{
item.@checked = checked;
}
item.@checked = checked;
toggleParents(tree.getParentItem(item), tree, checked);
}
}
答案 0 :(得分:0)
您必须通知集合数据已更改。这将通知树更新它的视图(在项目渲染器中设置数据设置器)。
类似于:
collection.itemUpdated(node, "@checked");
如果您不使用XML列表集合,则需要使用它。
var collection:XMLListCollection = new XMLListCollection(xml);
然后,当您完成更改后,您可能需要致电:
collection.refresh();
你写的其他所有东西乍一看都很好。
*在手机上