如何在 angularjs $http 中检查 null
Posted
技术标签:
【中文标题】如何在 angularjs $http 中检查 null【英文标题】:how check null in angularjs $http 【发布时间】:2017-12-05 03:23:31 【问题描述】:我有数据 json 计划航班,但 json 没有显示所有信息。它只是返回 null 一些数据,并且所有数据都显示 null 已经存在。我想检查我的数据是否为空,我发布了同样的问题,但他对 jquery 的不同。
短代码:
nameApp.controller('bgwCtrl', function($scope, $http,$interval,labeltext,$timeout,$ionicLoading, $ionicPopup,arrivecss)
$scope.loading = true;
// Setup the loader
$ionicLoading.show(
content: 'Loading',
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 0
);
$scope.reload = function ()
$http.get("v1/airport.json?code=bgw")
.then(function(response)
$timeout(function ()
$ionicLoading.hide();
$scope.labeltext=labeltext;
$scope.check=arrivecss;
$scope.time= response.data.result.response.airport.pluginData.schedule.arrivals.timestamp;
var dailyData = response.data.result.response.airport.pluginData.schedule.arrivals.data;
console.log(response.data.result.response.airport.pluginData.schedule.arrivals.data);
$scope.dailyForecast = [null];
for(var i=0; i<25; i++)
$scope.dailyForecast[i] = callsin: dailyData[i].flight.identification.id,
callsign: dailyData[i].flight.identification.number.default,
statu: dailyData[i].flight.status.generic.status.text,
airline: dailyData[i].flight.airline.code.iata,
from: dailyData[i].flight.airport.origin.position.region.city,
timear: dailyData[i].flight.time.scheduled.arrival,
generic: dailyData[i].flight.status.text,
ident: dailyData[i].flight.identification.number.default,
timearrvie: dailyData[i].flight.time.estimated.arrival,
timearr: dailyData[i].flight.status.generic.eventTime.local,
model: dailyData[i].flight.aircraft.model.code,
icon: dailyData[i].flight.status.icon,
winir: dailyData[i].flight.airline.name,
;
console.log(response)
, 2000);
return response;
);
///response end///
function switchEstimated()
$scope.show=!$scope.show;
$interval(switchEstimated,3000);
$timeout(function()
$scope.reload();
,30000)
;
///reload end///
$scope.reload();
$scope.loading = false;
);
my data json
错误:departures[i].flight.airport.origin.position is undefined
【问题讨论】:
【参考方案1】:小心你要找的东西。我看到这条线
departures[i].flight.airport.origin.position
你说它给undefined
应该是
dailyData[i].flight.airport.origin.position
因为您已将 data
数组存储在 dailyData
中
【讨论】:
还是同样的问题【参考方案2】:您收到错误departures[i].flight.airport.origin.position is undefined
,因为它实际上是未定义的。如果您查看 JSON 数据的结构,您会发现:
departures:item:,page:,timestamp:value,data:[]
所以你必须改变你的电话如下:
departures.data[i].flight.airport.origin.destination.position
【讨论】:
还是同样的问题以上是关于如何在 angularjs $http 中检查 null的主要内容,如果未能解决你的问题,请参考以下文章