CTreeView is used to display Data with hierarchies, and TreeView is used to set Data attributes. Data is an array with the following structure: CTreeView is used to display Data with hierarchies, and TreeView is used to set Data attributes. Data is an array with the following structure:
Ext: string, the text of the tree node.
Expanded: boolean (optional) indicates whether to expand the node.
Id: string. (optional) ID of the node.
HasChildren: boolean. optional. the default value is False. if it is set to True, the node contains subnodes.
Children: array. (optional) array of child nodes.
HtmlOptions: array, HTML options.
So far, we have not introduced how to read the database. Therefore, the Hard Code data in this example is as follows:
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))))))));
Here, a link is added to the text of each node. it also demonstrates the use of JQuery to respond to node click events, which is achieved through the client JavaScripts.
Modify View definition
$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')));?>
The registerScript of clientScript is used to define JavaScripts on the client.
The above is the sample UI component TreeView in the PHP development Framework Yii Framework tutorial (19). For more information, see PHP Chinese website (www.php1.cn )!