我在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);
}
}
1条答案
按热度按时间jgwigjjp1#
您必须通知集合数据已更改。这将通知树更新其视图(在项目渲染器中设置数据设置器)。
它是这样的:
如果您没有使用XML列表集合,则需要使用它。
完成更改后,您可能 * 需要调用:
你写的其他东西乍一看都很好。