PHP development framework YiiFramework tutorial (19) UI component TreeView example

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.