繁体   English   中英

为什么我的Json数据没有使用angular ng-repeat显示在表中?

[英]Why my Json data is not display in table using angular ng-repeat?

在此处输入图片说明 我想显示从PHP文件返回的Json数据,如下所示:

“ {\\” success \\“:true,\\” message \\“:\\”找到交易记录。\\“,\\” user_transactions \\“:[{\\” user_id \\“:\\” 4 \\“,\\”金额充值\\“ :\\“ 4.00 \\”,\\“金额转帐\\”:\\“ 14400.00 \\”,\\“ app_rate \\”:\\“ 3600.00 \\”,\\“收费货币\\”:\\“ USD \\”,\\“收款人电话”:\\ “ 256775542757 \\”,\\“收款人名字_”:\\“ Sapkota \\”,\\“收款人姓氏” ::“ Suresh \\”,\\“收款人国家/地区”:\\“ UG \\”,\\“ transferred_currency \\”:\\“ UGX \\“,\\” transaction_status \\“:\\”已交付\\“,\\” order_id \\“:\\” 259 \\“,\\” created_date \\“:\\” 2017-07-25 13:35:48 \\“,\\” last_modified_date \\“:\\” 2017-07-25 13:35:48 \\“},{\\” user_id \\“:\\” 4 \\“,\\” amount_charged \\“:\\” 5.00 \\“,\\” amount_transferred \\“ :\\“ 18000.00 \\”,\\“ app_rate \\”:\\“ 3600.00 \\”,\\“ charged_currency \\”:\\“ USD \\”,\\“收款人电话\\”:\\“ 256775542757 \\”,\\“收款人名字_”:\\ “ Sapkota \\”,\\“收款人姓氏”:\\“ Suresh \\”,\\“收款人所在的国家/地区”:\\“ UG \\”,\\“ transferred_currency \\”:\\“ UGX \\”,\\“ transaction_status \\”:\\“已交付\\“,\\” order_id \\“:\\” 258 \\“,\\” created_date \\“:\\” 2017-07-25 06:23:05 \\“,\\” last_modified_date \\“:\\” 2017-07-25 0 6:23:05 \\“}]}”

使用Get像这样获取:

    $http.get("clients.php").then(function (response) {
    $scope.response = response;
    $scope.results = JSON.parse(response.data);

    console.log($scope.results);

}

问题是,在控制台.log中没有任何结果,在以这种方式编写的表行中也没有任何结果。 所以,有人请帮助我。

<table>
  <tr ng-repeat="result in results.user_transactions">


<td>{{ result.beneficiary_first_name}}</td>
<td>{{ result.transaction_status }}</td>

</tr>

</table>

您需要解析响应,因为它是字符串。

$http.get("clients.php").then(function (response) {
        $scope.response = response;
        $scope.results = JSON.parse(response.data);//Parsing string to JSON

        console.log($scope.results);

    }

<table>
  <tr ng-repeat="result in results.user_transaactions">

    <td>{{ res.beneficiary_first_name}}</td>//No need of using index of array
    <td>{{ res.transaction_status }}</td>
    </tr>

</table>

首先,您必须使用JSON.parse()将字符串结果解析为JSON。

$scope.results = JSON.parse(response.data);

在您的html中还有另一个问题

<table>
  <tr ng-repeat="result in results.user_transactions">
    <td>{{ result.beneficiary_first_name}}</td>
    <td>{{ result.transaction_status }}</td>
  </tr>
</table>

工作演示

暂无
暂无

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

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