我正在使用离子框架我正在将数据输入localStorage。
.controller('AppCtrl', function(Auth,$scope,$http, $ionicModal,$location,$state,$window,$localStorage, $sessionStorage,$timeout,$ionicSideMenuDelegate) {
//$scope.$on('$ionicView.leave', function () { $ionicSideMenuDelegate.canDragContent(true) });
$scope.adminData = $localStorage.adminData;
$scope.forgetData = $sessionStorage.forgetData;
$scope.levels = $localStorage.levels;
$scope.loginData = {}
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
$scope.levels = function() {
$http({
url: 'http://localhost/bearscoaching/api/classes',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'}
})
.then(function successCallback(response)
{
function isObjectHasData(object)
{
return (object != null && typeof object != 'undefined' && Object.keys(object).length > 0);
}
if(isObjectHasData(response.data))
{
$scope.dp = response.data;
$localStorage.levels = $scope.dp;
/*angular.forEach($localStorage.levels, function(user, arrayID)
{
alert(user.name);
});*/
$state.go('app.search');
}
else
{
alert("Data is not available");
//$state.go('app.dashboard');
}
}, function errorCallback(response)
{
console.log(response);
// $state.go('app.dashboard');
alert("Data is not available");
});
};
})
当我运行foreach循环时,我在alert中获取每个名称。但是当我在视图文件中获取这些数据时:
<ion-modal-view>
<ion-view view-title="Marie Simpson" id="mainpage" hide-nav-bar="false">
<ion-content padding="true" scroll="false">
<table>
<thead>
<th>Name</th>
</thead>
<tbody ng-repeat="item in levels">
<tr>
<td>{{item.name}}</td>
</tr>
</tbody>
</table>
</ion-content>
</ion-view>
</ion-modal-view>
我没有得到list.my的回复名称
ngStorage-levels: "[{"id":2,"name":"Level I"},{"id":3,"name":"Level I…":6,"name":"Level V"},{"id":7,"name":"Level VI"}]"