string(1) "0" ["id"] => string(1) "1" ["name"] => string(">
当前位置:Gxlcms > PHP教程 > 怎么用JavaScript或css在thinkPHP的模板中显示树形结构

怎么用JavaScript或css在thinkPHP的模板中显示树形结构

时间:2021-07-01 10:21:17 帮助过:5人阅读

后台的数据是这样子的
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 就行了 手册上面有 百度就知道了

人气教程排行