for循环问题
onLoad: function (options) { db.collection( 'users' ).where({ pid: app.globalData.openid }) .get().then(res => { console.log(res.data) var sons = res.data for ( var i = 0; i < res.data.length; i++) { console.log(i) //这里i=0 db.collection( 'users' ).where({ pid: res.data[i]._openid }) .get().then(res => { console.log(i) //这里i=1 sons[i-1].gsons = res.data }) } this .setData({ sons: sons }) console.log( this .data) }) }, |
为什么第一个i=0,第二个i=1