如何封装这个json,让其符合LayUI前端的JSON格式

应该如何更改前端代码,目前提示“返回的数据不符合规范”

http://127.0.0.1/conn.php  :

[{"comcname_d":"\u9ec4\u5357","yjpk_d":"2417047.29","sl":"721"},{"comcname_d":"\u6d77\u4e1c","yjpk_d":"13843905.83","sl":"1203"},{"comcname_d":"\u6d77\u5317","yjpk_d":"6153061.52","sl":"1857"},{"comcname_d":"\u6d77\u5357","yjpk_d":"1132748.40","sl":"412"},{"comcname_d":"\u7389\u6811","yjpk_d":"9625683.90","sl":"568"},{"comcname_d":"\u6d77\u897f","yjpk_d":"5032555.34","sl":"1978"},{"comcname_d":"\u683c\u5c14\u6728","yjpk_d":"2475259.80","sl":"506"},{"comcname_d":"\u897f\u5b81","yjpk_d":"28547051.91","sl":"5729"},{"comcname_d":"\u679c\u6d1b","yjpk_d":"374000.80","sl":"241"}]

前端:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>table模块快速使用</title>
		<link rel="stylesheet" href="/layui/css/layui.css" media="all">
	</head>
	<body>

		<table id="demo" lay-filter="test"></table>

		<script src="/layui/layui.js"></script>
		<script>
			layui.use('table', function() {
				var table = layui.table;

				//第一个实例
				table.render({
					elem: '#demo',
					height: 312,
					url: "http://127.0.0.1/conn.php" //数据接口
						,
					
					cols: [
						[ //表头
							{field: 'comcname_d',title: '地市名',width: 80,sort: true,fixed: 'left'},
							{field: 'yjpk_d',title: '已决金额',width: 100,sort: true,//排序符号 
							}, 
							{field: 'sl',title: '已决件数',width: 100,sort: true}
						]
					]
				});

			});
		</script>
	</body>
</html>

 

查看全部
Newbee_Mofi
Newbee_Mofi
2020/12/03 20:39
  • json
  • php
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复