2017-07-27 47 views
-1

enter image description here我想显示从PHP文件返回因为这样我JSON数据:为什么我的Json数据没有使用角度ng-repeat显示在表格中?

“{\” 成功\ “:真实的,\” 消息\ “:\”。交易纪录发现\ “\” user_transactions \ “:[{\” USER_ID \ “:\” 4 \ “\ ”amount_charged \“:\ ”4.00 \“,\ ”amount_transferred \“:\ ”14400.00 \“,\ ”app_rate \“:\” 3600.00 \ “\ ”charged_currency \“:\ ”USD \“,\ ”beneficiary_phone \“:\ ”256775542757 \“,\ ”beneficiary_first_name \“:\ ”Sapkota \“,\ ”beneficiary_last_name \“:\” 苏雷什\ ”,\ “beneficiary_country \”:\ “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 \ “\ ”beneficiary_phone \“:\ ”256775542757 \“,\” 是neficiary_first_name \ “:\” Sapkota \ “\ ”beneficiary_last_name \“:\ ”苏雷什\“,\ ”beneficiary_country \“:\ ”UG \“,\ ”transferred_currency \“:\ ”UGX \“,\” transaction_status \ “:\”Delivered \“,\”order_id \“:\”258 \“,\”created_date \“:\”2017-07-25 06:23:05 \“,\”last_modified_date \“:\”2017 -07-25 06: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> 
+0

您的数据串。首先使用JSON.parse解析它uisng() – Ved

+0

为什么你不安慰响应?先检查一下。 –

+0

控制台响应,我得到:对象{数据:“”{\“成功\”:真,\“消息\”:\“交易历史...”last_modified_date \“:\”2016-11-01 16:55 :31 \“}]}”“,status:200,config:Object,statusText:”OK“,headers:function} –

回答

1

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

$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> 
1

首先,您必须使用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> 

Working Demo

+0

嗨,Jain,现在我已经得到了conson.log中的数据在JSON.parsse()之后,但仍然没有任何内容显示在使用您的代码的表中,您是否可以通过再次检查来帮助我 –

+0

您是否可以相应更新工作演示?以便我可以看到您的错误? –

+0

你能告诉我console.log($ scope.results)的结果吗? ? –

相关问题