let arrl:any=[]
wx.request({
url:`${ull}/db/list.php?where=classid>0`,
success(res){
console.log(res.data);
that.setData({arrl:res.data})
console.log(arrl);
打印出来的arrl=[],空,导致我后面没有办法进行数据分组;如果把第一行和最后一行去掉,后面for(let i = 0;i <arrl.length;i++)会报错:找不到名称arrl。
这可如何是好?
1、把第一行去掉,即:let arrl = []
2、最后一行改成:console.log(that.arrl)
3、以后全页引用this.arrl。
我觉得你还是提交一个代码片段吧,我觉得应该是你代码问题,你在评论里面写的,都只是部分,不好找的问题
在success里面,先不要赋值,直接处理数据
处理好数据后,再赋值
let arrl = res.data
console.log(arrl);
打印的确变了
(12) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "1", classid: "1", jobname: "Java程序员", position: "云龙区", pay: "7000", …}
1: {id: "2", classid: "1", jobname: "PHP程序员", position: "泉山区", pay: "8000", …}
2: {id: "3", classid: "1", jobname: "高级程序员", position: "云龙区", pay: "15000", …}
但是下面 let arrl = res.data
console.log(arrl); },
fail(err){console.log(err);}
})
let arrl1=[]
let arrl2=[]
for(let i = 0;i <arrl.length;i++){
if(arrl[i].classid==2){
会报错:找不到名称arrl
let arrl = [], 这样不能满足需求吗?
这样试试
nv_length: (...)
__proto__: Array(0)
0: {id: "1", classid: "1", jobname: "Java程序员", position: "云龙区", pay: "7000", …}
1: {id: "2", classid: "1", jobname: "PHP程序员", position: "泉山区", pay: "8000", …}
2: {id: "3", classid: "1", jobname: "高级程序员", position: "云龙区", pay: "15000", …}
3: {id: "4", classid: "2", jobname: "川菜厨子", position: "贾汪区", pay: "10000", …}
4: {id: "5", classid: "2", jobname: "鲁菜大厨", position: "云龙区", pay: "12000", …}
一组数据。前台{{arrl}}能用。我现在想分组提高效率