二级联动:map,for循环一级数据,调用接口获取对象数据依次放到数组里(解决由于后端java是多线程,接收到的数据放入(push)数组中有可能会顺序不对) (循环发送请求,返回结果没有按请求顺序排序)promise


解决方法1:遍历一级数据时先push一个新的对象,调用接口获取到数据之后splice方法通过index的值判断放入到数组的对应下标下
this.tableData一级数据:
 this.relationMaterialNameList二级数据:
this.tableData.map((item,index)=>{
                             this.relationMaterialNameList.push({})
                            // 编辑页面项目下拉框数据
                            this.getSpecificationList(item.reimbursementType, index)
     })
 
 // 项目下拉数据
            getSpecificationList(code, index) {
                // 项目下拉数据
                this.$axios({
                    url: `/chenfan_sample/sampleDevReim/relationMaterial?reimbursementType=${code}`,
                    method: 'get',
                }).then((res) => {
                    if (res.code === 200) {
                         this.relationMaterialNameList.splice(index, 1, res.obj)
                    }
                })
            },
解决方法2:promise all 是按顺序返回的


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM