繁体   English   中英

使用Angular.js访问php数组数据

[英]Using Angular.js to access php array data

我已经问了这样的问题,但我遇到了问题。 我正在使用angular.js将数据发送到php文件。 这个php文件正在收集数据列表并将其存储在一个数组中。 然后我编码这个数组并将其发送回成功函数的角度。 我需要一个接一个地显示每个数组。

有什么建议么 ?

if($result){
 while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){


  $Participants = array(
            firstname => $row['firstname'],
            lastname => $row['lastname'],
            amount => $row['longitude']
        );


 }

}

echo json_encode($Participants);

我有棱有角

     angular.forEach(response.data, function(value, key){

        var Participants = {};

        Participants = {

          firstname: value['firstname'],
          lastname: value['lastname'],
          amount: value['amount'], 
        };

        console.log(Participants);

        });

您的阵列只会容纳一个参与者。 在循环上方声明它,并在其中附加到:

$Participants = array();

if($result) {
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){

        $Participants[] = array(
            firstname => $row['firstname'],
            lastname => $row['lastname'],
            amount => $row['longitude']
        );
}

您的客户端角度代码中存在类似的问题:

// Note this is now an array instead of plain object
var Participants = []; 
angular.forEach(response.data, function(value, key){
    Participants.push({
        firstname: value['firstname'],
        lastname: value['lastname'],
        amount: value['amount'], 
    });
});


console.log(Participants);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM