怎麼用JavaScript或css在thinkPHP的模板中顯示樹形結構

來源:互聯網
上載者:User
背景資料是這樣子的
array(2) {  [0] => array(4) {    ["pid"] => string(1) "0"    ["id"] => string(1) "1"    ["name"] => string(9) "江西省"    ["son"] => array(2) {      [0] => array(3) {        ["pid"] => string(1) "1"        ["id"] => string(1) "2"        ["name"] => string(9) "南昌市"      }      [1] => array(4) {        ["pid"] => string(1) "1"        ["id"] => string(1) "3"        ["name"] => string(9) "贛州市"        ["son"] => array(1) {          [0] => array(3) {            ["pid"] => string(1) "3"            ["id"] => string(1) "4"            ["name"] => string(9) "大田鄉"          }        }      }    }  }  [1] => array(4) {    ["pid"] => string(1) "0"    ["id"] => string(1) "6"    ["name"] => string(12) "黑龍江省"    ["son"] => array(1) {      [0] => array(3) {        ["pid"] => string(1) "6"        ["id"] => string(1) "5"        ["name"] => string(12) "哈爾濱市"      }    }  }}

怎麼在前台輸出來,資料有可能會變化。換句話說不能寫死樣式。求指導


回複討論(解決方案)

你是寫css 還是寫tp的標籤啊 ?這個樹有幾層 也是未知的嘛 tp模版就volist標籤 然後判斷是否有son,有son是一種樣式 沒有son是另外一種樣式

tp的標籤能提供一下代碼麼

首先你要迴圈 就用volist foreach 都可以 判斷就用 if 就行了 手冊上面有 百度就知道了

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.