可以通过labelFunction来自定义ComboBox、tree等组件的显示内容。有时我们需要统计非叶子节点子节点的个数。利用labelFunction就可以很容易的实现该功能,当然也可以通过itemRenderer实现。
private function tree_labelFunc(item:XML):String {
var children:ICollectionView;
var suffix:String = "";
if (tree.dataDescriptor.isBranch(item)) {
children = tree.dataDescriptor.getChildren(item);
suffix = " (" + children.length + ")";
}
return item[tree.labelField] + suffix;
}
<mx:Tree id="tree"
dataProvider="{dp}"
showRoot="false"
labelField="@label"
labelFunction="tree_labelFunc"
width="300"
rowCount="6"
itemClick="tree_itemClick(event);" />
利用itemRenderer实现labelFunction的功能。
package myComponents
{
// itemRenderers/tree/myComponents/MyTreeItemRenderer.as
import mx.controls.treeClasses.*;
import mx.collections.*;
public class MyTreeItemRenderer extends TreeItemRenderer
{
// Define the constructor.
public function MyTreeItemRenderer() {
super();
}
// Override the set method for the data property
// to set the font color and style of each node.
override public function set data(value:Object):void {
super.data = value;
if(TreeListData(super.listData).hasChildren)
{
setStyle("color", 0xff0000);
setStyle("fontWeight", 'bold');
}
else
{
setStyle("color", 0x000000);
setStyle("fontWeight", 'normal');
}
}
// Override the updateDisplayList() method
// to set the text for each tree node.
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(super.data)
{
if(TreeListData(super.listData).hasChildren)
{
var tmp:XMLList =
new XMLList(TreeListData(super.listData).item);
var myStr:int = tmp[0].children().length();
super.label.text = TreeListData(super.listData).label +
"(" + myStr + ")";
}
}
}
}
}
分享到:
相关推荐
()}" labelFunction="selectDateTime" width="150"/> public function selectDateTime(item:Date):String { return item.fullYear + "-" + item.month + "-" + item.dateUTC + " " + item.hours + ":" + ...
如果仅仅只是简单的显示数据,或者对显示数据做一些格式化操作,基本的DataGrid,加labelFunction支持就可以满足了,但大多我们需要针对不同的数据和对象,进行不同的渲染,比如checkbox啦,下拉选择框,日期等等,...
设置控件的labelFunction 2.7节. 提供菜单数据 2.8. 动态填充菜单 2.9节. 为菜单类控件创建事件处理函数 2.10节. 显示一个通知窗口 2.11节. 使用Calendar控件 2.12节. 弹出窗口的显示和位置 2.13节. 自定义弹出式...
改动文件:inc/LabelFunction.asp,admin/art_save.asp,admin/art_class_do.asp,template/class.htm,template/list.htm11、修正当添加修改文章,保存后自动生成html页面后不会自动返回问题12、新增网站描述,全站...
<base:HDateField id="flt_date" width="70" tabIndex="7" editable="true" labelFunction="formatDate" restrict="[A-Z,0-9]" text="{this.formatDate(new Date)}" validator="{fltDateValidator}" /> ...