jqueryif条件问题
我有一个推送数组的函数,但我遇到了问题,因为我的条件一直在一起检查。除此之外,如果我使用卷发文胸,我将获得创建数组的次数。即使我在这里无法正确解释,请查看我的代码:jqueryif条件问题,jquery,Jquery,我有一个推送数组的函数,但我遇到了问题,因为我的条件一直在一起检查。除此之外,如果我使用卷发文胸,我将获得创建数组的次数。即使我在这里无法正确解释,请查看我的代码: $.map(pObj,function(values,i){ if(typeof pieArray[values.GeoID] == 'undefined') pieArray[values.GeoID] = []; //it should create only one time pieArray
$.map(pObj,function(values,i){
if(typeof pieArray[values.GeoID] == 'undefined')
pieArray[values.GeoID] = []; //it should create only one time
pieArray[values.GeoID].push(values.ResponsePercentage); // when it matches it should not go down to check next if. else it can go.
if(!values.GeoID && typeof pieArray[0] == 'undefined')
pieArray[0] = []; //it should create only one time
pieArray[0].push(values.ResponsePercentage); //now the top if get response, till it is checking and throwing error. top if not match, then it need to work.
});
如何实现这一点?如果我正确理解您的问题,您只需使用控制块{}
我确实喜欢这个。它很好用
var pieArray = [];
var allIndia = false; //using as a key.
$.ajax({
cache: false,
type: "GET",
async: false,
url: url,
dataType: "jsonp",
success: function (pObj) {
$.map(pObj,function(values,i){
if(typeof pieArray[values.GeoID] == 'undefined') pieArray[values.GeoID] = [],allIndia = false;//making false
pieArray[values.GeoID].push(values.ResponsePercentage);
if(!values.GeoID && typeof pieArray[0] == 'undefined') pieArray[0] = [], allIndia = true;//making true, so it will not go down the first condition matches.
if(allIndia) {pieArray[0].push(values.ResponsePercentage)};
})
pieArray = $.grep(pieArray,function(n){
return(n);
});
console.log(pieArray);
makePieChart();
},
error: function (err) {
//console.log(err);
}
});
谢谢大家。请不要认为这是一种侮辱,但我不是一个以英语为母语的人,在你格式不好的问题和语法之间,我很难理解你在说什么。你能再解释一下吗,或者提供更多的代码?对不起。我找到了一些解决办法,问题得到了解决。谢谢。我就是这么说的,当我这样做的时候,'pieArray[values.GeoID]=[];'正在根据值创建次数。
var pieArray = [];
var allIndia = false; //using as a key.
$.ajax({
cache: false,
type: "GET",
async: false,
url: url,
dataType: "jsonp",
success: function (pObj) {
$.map(pObj,function(values,i){
if(typeof pieArray[values.GeoID] == 'undefined') pieArray[values.GeoID] = [],allIndia = false;//making false
pieArray[values.GeoID].push(values.ResponsePercentage);
if(!values.GeoID && typeof pieArray[0] == 'undefined') pieArray[0] = [], allIndia = true;//making true, so it will not go down the first condition matches.
if(allIndia) {pieArray[0].push(values.ResponsePercentage)};
})
pieArray = $.grep(pieArray,function(n){
return(n);
});
console.log(pieArray);
makePieChart();
},
error: function (err) {
//console.log(err);
}
});