首页 > 代码库 > js 循环获取值时-缓存数组(或集合)的长度
js 循环获取值时-缓存数组(或集合)的长度
$scope.footActiveIndex = 1;
$scope.noData = http://www.mamicode.com/false;
var iPageSize =10,
needRequest = true,//是否需要刷地址选择//是否要刷新loaddata
newCityPickerQu = [],//根据定位确定当前地址选择范围
num1,num2;//附近
$scope.info = {
area : ‘‘,
city : ‘‘,
businessscope : ‘‘,
address : ‘‘,
merchantname : ‘‘,
ticketcardtype : ‘‘,
businessscope : ‘‘,
projecttype : ‘‘,
pagesize : iPageSize,
};
var city = ‘‘, province = ‘‘;
if($rootScope.city){
city = $rootScope.city;
province = $rootScope.province;
}else{
$rootScope.city =‘北京市‘;
$rootScope.province = ‘北京市‘;
city = $rootScope.city;
province = $rootScope.province;
}
var refreshAddress= ()=>{
//
newCityPickerQu.splice(0,newCityPickerQu.length);
num1 = ‘‘;
num2=‘‘;
var ifshift = true;//是否删除第一行(除直辖市等,第三级默认第一位是该市)
// var length =CityPickerService.length;
for (var i = 0, max = CityPickerService.length; i < max; i++) {
// CityPickerService[i]
var cps = CityPickerService[i];
for (var j = 0, max = cpsSub.sub.length; j < max; j++) {
// cps.sub[j]
var cpsSub = cps.sub[j];
// if 1
if(cps.sub[j].name === $rootScope.city){
for (var m = 0, max = cpsSub.sub.length; m < max; m++) {
// cpsSub.sub[m]
if(cpsSub.sub[0].name == cps.sub[j].name){
ifshift = true;
}else{
ifshift = false;
}
// if 1>2
if(cpsSub.sub[m].name==$rootScope.district){
num1={
name:‘附近‘,
value:cpsSub.sub[m].value
}
num2={
name:‘全部‘,
value:cpsSub.sub[m].value
}
}
if(!num1){
num2={
name:‘全部‘,
value:cpsSub.sub[0].value
}
}
newCityPickerQu.push(cpsSub.sub[m]);
}
if(ifshift){
newCityPickerQu.shift();
}
//地址初始值设置
$scope.info.city = newCityPickerQu[0].value;
$scope.info.area = ‘‘;
if(num1){
newCityPickerQu.shift(num1);
}
if(num2 &&(!num1)){
newCityPickerQu.shift(num2);
}
$scope.areaData.list = newCityPickerQu;
$scope.areaData.select.name="全部";
$rootScope.cityCode = newCityPickerQu[0].value;
break;
}
}
}
if(needRequest){//左上角城市手动定位时,刷新loadData
needRequest = false;
$scope.refresh();
}
}
js 循环获取值时-缓存数组(或集合)的长度