二級聯動: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