CTreeView用來顯示具有層次結構的數據,使用TreeView 通過設置Data屬性。Data為具有下面結構的數組:
ext: string, 樹節點的文本.
expanded: boolean,可選,表示該節點是否展開.
id: string, 可選,該節點ID.
hasChildren: boolean, 可選,缺省為False,當為True表示該節點含有子節點.
children: array,可選,子節點數組。.
htmlOptions: array, HTML選項。
到目前為止我們還沒有介紹讀取數據庫,因此本例使用Hard Code的數據如下:
array( 'text' => '<a id="27" href="#">World:4</a>' , 'id' => '27' , 'hasChildren' => true, 'children' => array ( array( 'text' => '<a id="1" href="#">Europa:3</a>' , 'id' => '1' , 'hasChildren' => true, 'children' => array ( array( 'text' => '<a id="3" href="#">Germany:3</a>' , 'id' => '3' , 'hasChildren' => true, 'children' => array ( array( 'text' => '<a id="15" href="#">Munich:0</a>' , 'id' => '15' , 'hasChildren' => false, ), array( 'text' => '<a id="16" href="#">Stuttgart:0</a>' , 'id' => '16' , 'hasChildren' => false, ), array( 'text' => '<a id="5" href="#">Berlin:0</a>' , 'id' => '5' , 'hasChildren' => false, ) )), array( 'text' => '<a id="2" href="#">Norway:3</a>' , 'id' => '2' , 'hasChildren' => true, 'children' => array ( array( 'text' => '<a id="10" href="#">Stavanger:0</a>' , 'id' => '10' , 'hasChildren' => false, ), array( 'text' => '<a id="12" href="#">Oslo:0</a>' , 'id' => '12' , 'hasChildren' => false, ), array( 'text' => '<a id="11" href="#">Bergen:0</a>' , 'id' => '11' , 'hasChildren' => false, ))), array( 'text' => '<a id="4" href="#">United Kingdom:2</a>' , 'id' => '4' , 'hasChildren' => true, 'children' => array( array( 'text' => '<a id="13" href="#">London:0</a>' , 'id' => '13' , 'hasChildren' => false, ), array( 'text' => '<a id="14" href="#">Manchester:0</a>' , 'id' => '14' , 'hasChildren' => false, ))), array( 'text' => '<a id="7" href="#">Asia:3</a>' , 'id' => '7' , 'hasChildren' => true, 'children' => array ( array( 'text' => '<a id="18" href="#">Japan:0</a>' , 'id' => '18' , 'hasChildren' => false, ), array( 'text' => '<a id="20" href="#">China:0</a>' , 'id' => '20' , 'hasChildren' => false, ), array( 'text' => '<a id="19" href="#">Indonesia:0</a>' , 'id' => '19' , 'hasChildren' => false, ) )), array( 'text' => '<a id="9" href="#">America:4</a>' , 'id' => '9' , 'hasChildren' => true, 'children' => array ( array( 'text' => '<a id="23" href="#">Canada:0</a>' , 'id' => '23' , 'hasChildren' => false, ), array( 'text' => '<a id="24" href="#">United States:0</a>' , 'id' => '24' , 'hasChildren' => false, ), array( 'text' => '<a id="25" href="#">Mexico:0</a>' , 'id' => '25' , 'hasChildren' => false, ), array( 'text' => '<a id="26" href="#">Argentina:0</a>', 'id' => '26' , 'hasChildren' => false, ))), array( 'text' => '<a id="8" href="#">Africa:2</a>' , 'id' => '8' , 'hasChildren' => true, 'children' => array( array( 'text' => '<a id="22" href="#">Kenya:0</a>' , 'id' => '22' , 'hasChildren' => false, ), array( 'text' => '<a id="21" href="#">Tanzania:0</a>' , 'id' => '21' , 'hasChildren' => false ) ) ) )))));