PHP開發架構Yii Framework教程(19) UI 組件 TreeView樣本

來源:互聯網
上載者:User
CTreeView用來顯示具有階層的資料,使用TreeView 通過設定Data屬性。Data為具有下面結構的數組:

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樣本的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.