For循环当中调用了函数,不渲染图层,给自定义组件传值产生数据值丢失,如何解决?
[代码]_getCategoryDetail(currentIndex) {[代码][代码] [代码][代码]const shoesID = this.data.categories[currentIndex].shoesID[代码][代码] [代码][代码]const details = this.data.categories[currentIndex][代码][代码] [代码][代码]const categoryData = this.data.categoryData;[代码][代码] [代码][代码]for (let i = 0; i < shoesID.length; i++) {[代码][代码] [代码][代码]categoryData[currentIndex][i] = {[代码][代码] [代码][代码]title: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]image: [代码][代码]""[代码][代码] [代码][代码]}[代码][代码] [代码][代码]getShoesDetail(shoesID[i]).then(res => {[代码][代码] [代码][代码]categoryData[currentIndex][i].title = String(res.data[0]._shoesID)[代码][代码] [代码][代码]categoryData[currentIndex][i].image = String(res.data[0]._hostgraph)[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]this.setData({[代码][代码] [代码][代码]categoryData[代码][代码] [代码][代码]})[代码] [代码][代码] console.log(categoryData[currentIndex]) [代码]},[代码] [代码]--------------------------------------以上是category.js中的code---------------------------------------[代码] [代码]<w-content categoryDetail=[代码][代码]"{{categoryData[currentIndex]}}"[代码][代码]/>[代码] [代码]-------------------------------------以上是category.wxml中的code---------------------------------------[代码] [代码] [代码] 把上方category.js中categoryData[currentIndex]传给下方w-content.js中的categoryDetail [代码]-----------------------------------以下是自定义组件w-content中code-------------------------------------[代码] [代码]properties: {[代码] [代码] [代码][代码]categoryDetail: {[代码][代码] [代码][代码]type: Array,[代码][代码] [代码][代码]observer: function (newVal, oldVal) {[代码][代码] [代码][代码]console.[代码][代码]log[代码][代码](newVal)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]},[代码] getShoesDetail为调用的查询数据库函数,外面的this.setData不渲染图层,以下是两边打印的结果 [图片] 上方是w-content.js:9 下方是category.js:67