我有个问题与输出从MySQLAngularJS NG-重复未示出数据表
getCustomers.php是
$query="select distinct c.ancestry, c.trusted from members c order by c.id";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = json_encode($row);
}
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
和CONTROLER代码:
app.controller('customersCrtl', function ($scope, $http, $timeout) {
$http.get('ajax/getCustomers.php').success(function(data){
$scope.list = data;
$scope.currentPage = 1; //current page
$scope.entryLimit = 100; //max no of items to display in a page
$scope.filteredItems = $scope.list.length; //Initially for no filter
$scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.sort_by = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse;
};
});
问题是我从MySQL获得这种格式(例如):
["{\"ancestry\":\"12865794218\",\"trusted\":\"128\"}"]
,但可预期的是:
[{"ancestry":"1286794218","trusted":"126"}]
所以,如果我写的数据它工作完全正常
$scope.list = [{"ancestry":"1286794218","trusted":"126"}];
感谢您的帮助常数。
的“\”是正确的。当你捕获数组时,javascript显示错误? –
检查此答案以澄清反斜杠。 https://stackoverflow.com/a/10314758/8303694 –