时间:2021-07-01 10:21:17 帮助过:38人阅读
ext: string, 树节点的文本。
expanded: boolean,可选,表示该节点是否展开。
id: string, 可选,该节点ID.
hasChildren: boolean, 可选,缺省为False,当为True表示该节点含有子节点。
children: array,可选,子节点数组。
htmlOptions: array, HTML选项。
到目前为止我们还没有介绍读取数据库,因此本例使用Hard Code的数据如下:
array( 'text' => ' 'id' => '27' , 'hasChildren' => true, 'children' => array ( array( 'text' => ' 'id' => '1' , 'hasChildren' => true, 'children' => array ( array( 'text' => ' 'id' => '3' , 'hasChildren' => true, 'children' => array ( array( 'text' => ' 'id' => '15' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '16' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '5' , 'hasChildren' => false, ) )), array( 'text' => ' 'id' => '2' , 'hasChildren' => true, 'children' => array ( array( 'text' => ' 'id' => '10' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '12' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '11' , 'hasChildren' => false, ))), array( 'text' => ' 'id' => '4' , 'hasChildren' => true, 'children' => array( array( 'text' => ' 'id' => '13' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '14' , 'hasChildren' => false, ))), array( 'text' => ' 'id' => '7' , 'hasChildren' => true, 'children' => array ( array( 'text' => ' 'id' => '18' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '20' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '19' , 'hasChildren' => false, ) )), array( 'text' => ' 'id' => '9' , 'hasChildren' => true, 'children' => array ( array( 'text' => ' 'id' => '23' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '24' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '25' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '26' , 'hasChildren' => false, ))), array( 'text' => ' 'id' => '8' , 'hasChildren' => true, 'children' => array( array( 'text' => ' 'id' => '22' , 'hasChildren' => false, ), array( 'text' => ' 'id' => '21' , 'hasChildren' => false ) ) ) )))));
这里为每个节点的文本都添加了一个链接,同时也演示了使用JQuery响应节点的点击事件,这是 通过客户端JavaScripts来实现的。
修改View定义
$cs=Yii::app()->clientScript;
$cs->registerScript('menuTreeClick', "
jQuery('#menu-treeview a').click(function() {
alert('Node #'+this.id+' was clicked!');
return false;
});
");
$this->widget('CTreeView',array(
'id'=>'menu-treeview',
'data'=>DataModel::getDummyData(),
'control'=>'#treecontrol',
'animated'=>'fast',
'collapsed'=>true,
'htmlOptions'=>array(
'class'=>'filetree'
)
));
?>clientScript的registerScript用来做客户端定义JavaScripts。

以上就是PHP开发框架Yii Framework教程(19) UI 组件 TreeView示例的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!