0
我從服務器返回的數據$ scope中遇到了一個大問題$ apply函數剝離了這個值,我無法操作我的數據。
的數據從服務器返回:
angular.callbacks._0([{'Empresa':'Solução Informática','Email':'[email protected]','Filial':'1','Pontos':'504,23'},{'Empresa':'Keiken Sushi Bar e Restaurante ','Email':'[email protected]','Filial':'7','Pontos':'154,48'}])
從該應用中的打印:
來自控制器的代碼:
.controller('meusPontosCtrl', function($scope, $http, $localStorage,$ionicLoading, $timeout, $ionicPopup,$state,$stateParams,$window, MeusPontos,pontos) {
$scope.$on('$ionicView.enter', function(){
$http.get('https://ssl-386475.uni5.net/bonus/ClienteIOS/meuspontos?id='+$localStorage.user.Id+'&callback=JSON_CALLBACK')
.success(function(response, status, headers, config){
$ionicLoading.show({
content: 'Carregando Dados',
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 0
});
$timeout(function() {
$ionicLoading.hide();
//response = response.replace('angular.callbacks._0(','').replace(')','').replace('""','');
$scope.$apply(function() {
$scope.pontos = response
console.log(response)
})
}, 1000);
})
})
})
從HTML的代碼模板:
<ion-view title="Meus Pontos">
<ion-content overflow-scroll="true" class="has-header" ng-controller="meusPontosCtrl">
<ion-list>
<ion-item ng-repeat="item in pontos track by $index" type="item-text-wrap" data-ng-click="selecionado(item)" >
<img src="img/ic_action11.png" style="float:left; width:48px; heigth:48px; margin-right:24px">
<h2>Creditos R$ {{item.Pontos}}</h2>
<p>{{item.Empresa}}</p>
<p>{{item.Email}}</p>
</ion-item>
</ion-list>
</ion-content>
你究竟想要達到什麼目的?您想將響應轉換爲JSON格式嗎? – Dexter