我有個問題與輸出從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 –