这周主要就是对bug进行修改,然后自己也是遇见一个问题,困扰了我好长时间,就是根据上一级的数据渲染下一级的数据,这样得使用到promise异步处理,自己也是弄了好长时间,招人问了,终于解决了
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| function bns(id,name,names,othername,numbers){ return new Promise((resolve, reject) => { axios({ method:'get', url:'/admins/selectOrganization', params:{ id:id, } }).then((date)=>{ // console.log(date.data); let all = date.data.data; let html = `<dd class="layer-select-tips layer-this ${names}" >请选择</dd>`; for(let i=0;i<all.length;i++){ html += `<dd class="layer-select-tips ${names}" value="${all[i].name}" id="${all[i].id}">${all[i].name}</dd>`; } layer_list[numbers].innerHTML = html; if(numbers == 1 ){ selectTitle(layer_click,academy,1); }else if(numbers == 2 ){ selectTitle(layer_click,major,2); }else if(numbers == 3){ selectTitle(layer_click,grade,3); } let clist = 'layer-this'; for(let j=0;j<name.length;j++){ if(name[j].innerHTML == othername){ console.log(name[j].innerHTML); console.log(othername); // switchover(name,i,clist); switchover(name,j,clist); let ids = name[j].id if(numbers != 3){ resolve(ids) } } } }).catch((err)=>{ console.log(err); }) }) }
|
一级一级渲染:
1 2 3 4 5 6 7 8 9
| fn(all[i].grade).then(function (value) { console.log(value) console.log(1) return bns(value,academy,'academy',layer_input[3].value,1); }).then((value) => { return bns(value,major,'major',layer_input[4].value,2); }).then((value) => { return bns(value,grade,'grade',layer_input[5].value,3); })
|
通过用promise对axios再封装,实现对数据的一级一级的获取。
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 fortunate!