时间:2021-07-01 10:21:17 帮助过:21人阅读
//示例1
[
{"id": "4","name": "服饰鞋类箱包"},
{"id": "8","name": "母婴"}
]
//示例2
[
{"value":{"id":4,"name":"服饰鞋类箱包" }},
{"value":{ "id":8,"name":"母婴"}}
]
目前获取到的结果是 如示例1 结构 ,
表中没有value字段
$tree = M('Kind')->where(array('status'=>1))->field('id, title as name')->select();
$this->ajaxReturn($tree);
想要获取 如示例2 的结构,有方便的方法吗?
框架是 thinkphp
//示例1
[
{"id": "4","name": "服饰鞋类箱包"},
{"id": "8","name": "母婴"}
]
//示例2
[
{"value":{"id":4,"name":"服饰鞋类箱包" }},
{"value":{ "id":8,"name":"母婴"}}
]
$tree = M('Kind')->where(array('status'=>1))->field('id, title as name')->select();
$return_data = array();
foreach ($tree as $val){
$return_data[] = array("value" => $val);
}
$this->ajaxReturn($return_data);