如何用json在角度js中进行ng-repeat

时间:2017-06-13 03:33:38

标签: php angularjs json

我在制作包含json数据的列表时遇到问题。我有一些像这样的json数据

[
  {
    "date time":"2017-05-15 12:45:24",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-15 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-15 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-16 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-16 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-18 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-19 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-19 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-19 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 },
 {
    "date time":"2017-05-19 12:45:32",
    "latitude":"-7.9786395",
    "longitude":"112.5617418"
 }
]

我想从每个日期的json制作列表,但如果我使用这个json,它希望每个数据的make list不是每个日期。或者我在PHP中的代码是错误的。

php代码

$sqlcode = $con->query("select `date time`, `latitude`, `longitude` from data WHERE `imei`='$w12' AND `latitude` < '212' AND `date time` BETWEEN '$w22-01 00:00:00' AND '$w22-31 23:59:59'", MYSQLI_USE_RESULT);
$jsonObj = array();
while ($result = mysqli_fetch_object($sqlcode)) {
    $jsonObj[] = $result;
}
$final_res = json_encode($jsonObj);
echo $final_res;

我想列出这样的列表http://plnkr.co/edit/e41n9vAMMLf0WWIUQ8HO?p=preview

1 个答案:

答案 0 :(得分:2)

抱歉延误。我使用AngularJS和UnderscoreJS生成了所需的JSON格式,因此我不熟悉PHP。请参考链接中的JSBin,您将获得格式化的JSON。在线美化它,您可以看到分组数据。请在代码中使用类似的循环,然后就可以实现它。我希望它会有所帮助。我包含了underscore.js内联,它没有在JSBin中在线加载。谢谢。

JSBin Link

嵌入式 <a class="jsbin-embed" href="https://jsbin.com/vipicus/embed?html,js,output">JS Bin on jsbin.com</a><script src="https://static.jsbin.com/js/embed.min.js?4.0.4"></script>