Home >Backend Development >PHP Tutorial >在获取的结果中增加一个对象名称

在获取的结果中增加一个对象名称

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:09:07961browse

目前获取到的结果是 如示例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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn