前台: dhtmlxgrid.显示数据
其格式为:
{ rows:[ {id:1,data:[1,2,3]} ,{} ]}
如果在postgesql里直接生成这样的串呢??
这是就今天要做的事.
也是测试了一天,还是别人的帮助下完成:
1,2 本人自己写的,怎么也达不成这个目标:
3, 群友给的方案:完美解决
--方案1: select json_agg(row_to_json(t))::text from (select id,concat_ws(‘,‘,pt_name,pt_description) as mydata from project_template )as t; --结果[{"id":1,"myData":"whq,admin"},{"id":2,"myData":"eathon,sys"}] --不理想 --方案2: select json_agg(row_to_json(t))::text from (select id,‘[‘|| concat_ws(‘,‘,pt_name,pt_description) ||‘]‘ as mydata from project_template ) as t --结果[{"id":1,"myData":["whq,admin"]},{"id":2,"myData":["eathon,sys"]}] 好像对了,可是仔细看:"myData":["eathon,sys"] 不对,应该是:"myData":["eathon","sys"] --方案3: select json_agg(row_to_json(t))::text from (select id,array[pt_name,pt_description] as mydata from project_template where 1=1 and id=1) as t --结果:[{"id":1,"myData":["whq","admin"]},{"id":2,"myData":["eathon","sys"]}]
时间: 2024-10-27 09:57:11