Maison >développement back-end >tutoriel php >在获取的结果中增加一个对象名称
目前获取到的结果是 如示例1 结构 ,
表中没有value字段
$tree = M('Kind')->where(array('status'=>1))->field('id, title as name')->select();
$this->ajaxReturn($tree);
想要获取 如示例2 的结构,有方便的方法吗?
框架是 thinkphp
<code>//示例1 [ {"id": "4","name": "服饰鞋类箱包"}, {"id": "8","name": "母婴"} ]</code>
<code>//示例2 [ {"value":{"id":4,"name":"服饰鞋类箱包" }}, {"value":{ "id":8,"name":"母婴"}} ]</code>
目前获取到的结果是 如示例1 结构 ,
表中没有value字段
$tree = M('Kind')->where(array('status'=>1))->field('id, title as name')->select();
$this->ajaxReturn($tree);
想要获取 如示例2 的结构,有方便的方法吗?
框架是 thinkphp
<code>//示例1 [ {"id": "4","name": "服饰鞋类箱包"}, {"id": "8","name": "母婴"} ]</code>
<code>//示例2 [ {"value":{"id":4,"name":"服饰鞋类箱包" }}, {"value":{ "id":8,"name":"母婴"}} ]</code>
<code>$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);</code>