全局变量没有值
问题描述
在进行赋值操作之后,全局变量的内容为空。
问题出现的环境背景及自己尝试过哪些方法
谷歌浏览器。使用var来定义全局变量,一样不生效。
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
$scope.collection={};
$scope.list={};
$scope.controlMap={};
$scope.initzhanquzhang=function(){
$http({
method:'POST',
url:'Report/ReportSearch',
data:{ReportSearchCode:"getSalesKqDataBuManager3",salesDateStr:$scope.searchData.salesDateStr,kindCode:$scope.kindCode}
})
.success(function(result, status, headers, config){
angular.forEach(result,function(data,index,array){
//给collection赋值kindCodeAndBuName,并申明为数值。
var buName=data.buName;
var kindCode = data.kindCode;
var kindCodeAndBuName=kindCode+"_"+buName;
$scope.collection[kindCodeAndBuName]=[];
$scope.list[kindCodeAndBuName]=[];
$scope.controlMap[kindCodeAndBuName]=null;
});
$http({
method:'POST',
url:'Report/ReportSearch',
data:{ReportSearchCode:"getSalesKqDataDetailBuManager3",salesDateStr:$scope.searchData.salesDateStr,kindCode:$scope.kindCode}
})
.success(function(result, status, headers, config){
angular.forEach(result,function(data,index,array){
//把结果分战区和渠道,并给相应的数组添加值。
var buName=data.buName;
var kindCode = data.kindCode;
var kindCodeAndBuName=kindCode+"_"+buName;
if($scope.collection.hasOwnProperty(kindCodeAndBuName) ){
if(data.longitude && data.latitude ){
$scope.collection[kindCodeAndBuName].push(new BMap.Point(data.longitude,data.latitude));
}
$scope.list[kindCodeAndBuName].push(data);
}
});
alrt(JSON.stringify($scope.list));
/*$http({
method:'POST',
url:'Report/ReportSearch',
data:{ReportSearchCode:"getSalesKqDataBuManager3",salesDateStr:$scope.searchData.salesDateStr,kindCode:$scope.kindCode}
})
.success(function(result, status, headers, config){
angular.forEach(result,function(data,index,array){
var buName=data.buName;
var kindCode = data.kindCode;
var kindCodeAndBuName=kindCode+"_"+buName;
var options = {
size: BMAP_POINT_SIZE_SMALL,
shape: BMAP_POINT_SHAPE_STAR,
color: 'yellow',
scale: 0.5
}
if($scope.controlMap.hasOwnProperty(kindCodeAndBuName) ){
$scope.controlMap[kindCodeAndBuName] = new BMap.PointCollection($scope.collection[kindCodeAndBuName], options);
}
});
});*/
});
});
};
$scope.initzhanquzhang();
alert(JSON.stringify($scope.collection));
你期待的结果是什么?实际看到的错误信息又是什么?
期望看到变量里面是有值的。时间看到的是{}。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http
请求是一个异步操作,在success回调之前,不会执行回调中的代码。然而你的取值是在发起请求之后就立即取值的。