2016-12-01 72 views
1

我有问题,在表上部署JSON效应初探, 这是我controller.js显示JSON与HTML表格角度

var app = angular.module('angularjs-starter', []); 
app.controller('MainCtrl', function($scope, $http) { 

$scope.choices = [{id: 'choice1'}]; 
$scope.jsonData = {}; 

这是我controler.js,我发布的数据里面的功能我与我的表中的内容

$scope.continue = function(choices) 
{ 
var json = $scope.choices; 

$http.post('php/calculador.php', json) 
.then(function(response) { 

    $scope.jsonData = response; 
    console.log($scope.jsonData); 

}); 


}; 
}); 

我印在控制台中的JSON数据,以确保数据是正确的,它是,但它并不在我的HTML表格显示任何数据PHP响应

这是我的HTML表格 当我试图部署的json

<div ng-app="angularjs-starter" ng-controller="MainCtrl"> 
<table> 
<tr ng-repeat="x in jsonData"> 
<td>{{ x.costo_m }}</td> 
<td>{{ x.desc }}</td> 
<td>{{ x.id }}</td> 
</tr> 

这是印在控制台

Object 
data:Array[1] 
    0: Array[1] 
     0: Object 
     costo_m: 18.973529411765 
     desc: "BLONG-F25+MOBICTRL" 
     id: "choice1" 
     licencias: 4.3 

回答

0

jsonData不是一个数组,它是一个对象,似乎有一个属性data,然后它包含一个数组数组。尽管如此,内部数组似乎是你想要的。

所以,仅仅用$scope.jsonData = response.data[0];

+0

更换$scope.jsonData = response;哦对不起我忘了后,我已经尝试,没有工作:( – Alex

+0

我不好。我又看了一下,它实际上似乎'response.data'不是array,但是是一个数组数组,但我对数据本身并不了解,但是似乎你需要'response.data [0]'来告诉我这是否正确,我会更新我的答案 – lucasnadalutti

+0

是啊工作!!!谢谢! – Alex