[英]Why isn't my function displaying data?
AngularJS AngularJS
$scope.getData = function(time) {
console.log(time + " get");
$http({
method: 'GET',
url: 'https://api.parse.com/1/classes/appointments',
params: {
time: time
},
headers: {
'X-Parse-Application-Id': 'XXXXX',
'X-Parse-REST-API-Key': 'XXXXX',
}
}).success(function(response, params, status, data, headers, config) {
console.log();
$scope.appts = data;
}).error(function(params, status) {
console.log(time + " eror");
});
};
HTML 的HTML
<ion-view title="Appointments" right-buttons="rightButtons">
<ion-content has-header="true" has-tabs="true" padding="true">
<button class="button button-light" ng-click="getData()"> button-light </button>
<ul>
<li ng-repeat="item in appts"> {{ appts.time }} </li>
</ul>
</ion-content>
</ion-view>
Now according to the console, its working but its not displaying a list of the data. 现在,根据控制台,它可以正常工作,但不显示数据列表。
Payload is this (just one for now) however... its still not showing the "time" 有效负载就是这个(现在只是一个)......仍然没有显示“时间”
{
"results": [{
"createdAt": "2015-12-30T15:03:48.511Z",
"objectId": "BjP1zZ8JqD",
"time": "12:24",
"updatedAt": "2015-12-30T15:03:48.511Z"
}]
}
Because you are not accessing the data correctly, 由于您没有正确访问数据,
First you do: 首先,您要做的是:
$scope.appts = data;
Which means to get at the first time you would need to access results
first then the array then time
这意味着获得在第一时间,你将需要访问
results
第一则数组,然后time
$scope.appts.results[0].time
What you probably actually want is 您可能真正想要的是
$scope.appts = data.results;
Since results
is the actual array of data 由于
results
是实际的数据数组
Second you are using the wrong angualr expression 其次,您使用了错误的角度表达式
<li ng-repeat="item in appts"> {{ appts.time }} </li> </ul>
appts
is the full array not one of the objects in the array, that would be item
appts
是完整数组,而不是数组中的对象之一,即为item
<li ng-repeat="item in appts"> {{ item.time }} </li> </ul>
If I don't read wrong you have the below response: 如果我没看错的话,您会收到以下回应:
{"results":[{"createdAt":"2015-12-30T15:03:48.511Z","objectId":"BjP1zZ8JqD","time":"12:24","updatedAt":"2015-12-30T15:03:48.511Z"}]}
and in the HTML code you refer to appts.time, but you must refer to appts.results [0].time. 并且在HTML代码中,您引用的是appts.time,但是您必须引用的是appts.results [0] .time。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.