【问题标题】:How to display array of objects php in angular js table?如何在角度js表中显示对象数组php?
【发布时间】:2017-07-08 20:08:37
【问题描述】:

我开始使用 Angular 和 PHP。我有一个 JSON 数组,它通过$http 调用将 PHP 文件发送到 AngularJS 函数,但我无法在函数 js 中获取 JSON 数组值。

带有控制台日志的json结果是:

php函数:

foreach ($result as $row) {
   $out[] = $row;  
}

echo json_encode($out);

js:

app.controller('controllerJs', ['$scope', '$http', function($scope,$http){
$scope.clients = [];

$scope.All = function(){
   $http.get('/App/getAll.php')
           .then(function(data){
              $scope.clients = data;
           });
}

}]); 

php 表:

 <tbody>
    <tr ng-repeat="item in clients">
      <td>{{item.nombre}}</td>
      <td>{{item.especialidad}}</td>
    </tr>
 </tbody>

【问题讨论】:

  • $scope.clients = data; ==> $scope.clients = data.data;
  • 小点 foreach ($result as $row) { $out[] = $row; } echo json_encode($out); 为什么不只是 json_encode($result); 并保存所有这些浪费的 CPU 周期

标签: javascript php angularjs function response


【解决方案1】:

您应该访问响应的 data 属性,

$scope.All = function(){
   $http.get('/App/getAll.php')
           .then(function(data){
       $scope.clients = data.data;
   });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多