ajax调用在回调函数里for循环加if判断出现问题

https://img2.mukewang.com/5c3c39140001188a11140588.jpg

结果第一条没出现 if大于0的判断走了 但宽度没加上 如图

https://img2.mukewang.com/5c3c39200001d5f104890298.jpg

https://img3.mukewang.com/5c3c392900013a7606210482.jpg

一直卡在这 请大手帮忙看一下

HUX布斯
浏览 1109回答 1
1回答

芜湖不芜

应该是这样写。。。。。我太菜鸟了 这个问题有点白痴。。。。。wbar:function(){&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type:"get",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url:bar_url,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType:"json",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success:function(data){//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var str = "";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(i in data.data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str += '<div class="row'+i+' clearall row"><div class="data_name">'+data.data[i].name+'</div><div class="data_bar clearall"><div class="bar_r" title="'+data.data[i].oValue+'"><div class="remove_bar" title="'+data.data[i].oValue+'"></div></div><div class="add_bar" title="'+data.data[i].tValue+'"></div></div><div class="bar_num">'+data.data[i].tValue+'</div></div>';//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(".barData").html(str);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(i in data.data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tv = data.data[i].tValue * 0.23;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ov = data.data[i].oValue * 0.23;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dv = data.data[i].dValue*0.23;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rv = data.data[i].rValue*0.23;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(tv);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).find(".data_bar").width(tv);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ifbar(data.data[i].dValue,i);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; }};page.init();function ifbar(d,i){&nbsp; &nbsp; if(d>0){&nbsp; &nbsp; &nbsp; &nbsp; console.log("nima");&nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).children(".data_bar").children(".bar_r").children(".remove_bar").width(0);&nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).children(".data_bar").children(".bar_r").width(ov);&nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).children(".data_bar").children(".add_bar").width(dv);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }else{//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(data.data[i].dValue);&nbsp; &nbsp; &nbsp; &nbsp; console.log(i);&nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).children(".data_bar").children(".add_bar").width(0);&nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).children(".data_bar").children(".bar_r").children(".remove_bar").width(rv);&nbsp; &nbsp; &nbsp; &nbsp; $(".row"+i).children(".data_bar").children(".bar_r").width(ov);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; };}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript