[youzan/vant]picker 联动 change 事件 索引可能越界

2024-05-22 499 views
4

picker二级联动,在change事件中通过picker.getIndexes()获取所有列索引,第二列的索引可能会超出数组长度,好像是随机出现的,没能找到规律

回答

8

补充一下,发现都是在滑动第一列的时候出现,滑动第二列好像没出现过

0

@Jarvay 能否贴一下你两列联动的代码?

9

@chenjiahan created:function(){ axios.get('/concur/service').then((res) =>{ this.serviceList = res.data; this.colums = [ { values:this.serviceList.map((parent) =>{ return parent.name; }) }, { values:this.serviceList[0].children.map((child) =>{ return child.name; }), defaultIndex:0 } ]; }); }

serviceChange:function(picker, values){ this.picker= picker; const index = picker.getColumnIndex(0); picker.setColumnValues(1, this.serviceList[index].children.map((child) =>{ return child.name; })); const indexes = this.picker.getIndexes(); // if(this.serviceList[indexes[0]].children > indexes[1]){ this.serviceId = this.serviceList[indexes[0]].children[indexes[1]].id; // } console.log(indexes); } 不知道怎么弄,粘贴出来代码连一起了

5

好吧,我再看看