PHP Development Framework Yii Framework Tutorial (UI component) TreeView example

Source: Internet
Author: User
Tags php framework yii
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!

  • 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.