假設資料庫中會計科目資料表的欄位為:id,code,name,islast。分別為自增主鍵,科目編碼,科目名稱,是否為末級("1"表示末級科目)。這裡在Thinkphp的模型層中使用遞歸來建構ComboTree所需的數據,程式碼及註解如下:
AccountModel = ->field('id,code,name,islast')->( & = (['code'( == 3['pid'] = 0['pid'] = (['code'],0,-2 ->createTree( createSubTree(, = ( =>(['pid'] == = 'id' => ['id'], 'text'=>['name'], 'state'=>(['islast'] != 1)?'closed':'open'(['islast'] != 1 = ->createSubTree(,['code'(!(['children'] = (, createTree( = ( => (['pid'] == 0 = 'id' => ['id'], 'text'=>['name'], 'state'=>'closed' = ->createSubTree(,['code'(!(['children'] = [] =
類似上述的數據(如部門,地區等)需要建構樹形選單的簡單修改程式碼後基本上都能實現類似功能。
以上是ThinkPHP+EasyUI的實例解說的詳細內容。更多資訊請關注PHP中文網其他相關文章!