The CTreeView is used to display hierarchical data by using the TreeView by setting the DataSource property. Data is an array with the following structure:
Ext:string, the text of the tree node.
Expanded:boolean, optionally, indicates whether the node is expanded.
Id:string, optional, the node ID.
Haschildren:boolean, optional, false by default, when True indicates that the node contains child nodes.
Children:array, optional, sub-node array.
Htmloptions:array, HTML options.
So far we haven't introduced the read database, so this example uses hard code with the following data:
Array (' text ' = = ' id ' = ' + ', ' haschildren ' = ' + ', ' Children ' =>array (' text ' = ' = ' id ' = ' 1 ', ' HasChildren ' + true, ' children ' =>array (Array (' text ' = ' = ' id ' = ' 3 ', ' haschildren ' = ' = ' = ' Children ' Gt;array (' text ' = ' + ' id ' = ' + ', ' haschildren ' = false, '), Array (' text ' = ' = ' id ' = ' + ', ' haschild ') ren ' = ' and False, ' array (' text ' = ' + ' id ' = ' 5 ', ' haschildren ' = ' = ') '), Array (' text ' = ' = ' id ' = ' 2 ') , ' haschildren ' = true, ' Children ' =>array (' text ' = ' + ' id ' = ' + ', ' haschildren ' = false, '), Array (' Text ' = ' + ' id ' = ' + ', ' HasChildren ' and ' false ', array (' text ' = ' = ' id ' = ' one ', ' haschildren ' = False )), array (' text ' = = ' id ' = ' 4 ', ' haschildren ' = ' = ', ' Children ' =>array (' text ' = ' + ' id ' = ' = ') ', ' HasChildren ' and ' false, ', Array (' text ' = ' + ' id ' = ' + ', ' haschildren ' = False, ') '), Array (' text ' = = ') ' id ' = ' 7 ', ' Haschildren ' = True, ' Children ' =>array (Array (' text ' = = ' id ' = ' + ', ' haschildren ' = false, '), Array (' text ' = = ' id ' = ' + ', ' haschildren ' and ' = False ', ' Array (' text ' = ' + ' id ' = ' + ', ' haschildren ' = ' = False, ') '), Array ( ' text ' + = ' id ' = ' 9 ', ' haschildren ' = ' = ', ' Children ' =>array (Array (' text ' = ' = ' id ' = ' ", ' Hasch Ildren ' and False, ' array (' text ' = = ' id ' = ' + ', ' haschildren ' = false, '), Array (' text ' = = ' id ' = ' 2 5 ', ' haschildren ' = False,), array (' text ' = = ' id ' = ' + ', ' haschildren ' = ' = False, ') '), Array (' text ' = = ') ID ' = ' 8 ', ' haschildren ' = ' = ', ' Children ' =>array (Array (' text ' = ' + ' id ' = ' + ') ', ' haschildren ' = FA LSE,), array (' text ' = ' + ' id ' = ' + ', ' HasChildren ' + false)))));
This adds a link to the text for each node, and also shows the click events using the jquery response node, which is done through the client javascripts.
Modify the 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 ClientScript registerscript is used to do client-side definition javascripts.
The above is the content of the PHP Framework Yii Framework Tutorial (topic.alibabacloud.com) UI component of the TreeView sample, and more about the content, please focus on the www.php.cn!