写了这么一个方法:
//依次请求每个人的部门信息
for(let i=0;i<this.logData.length;i++){
let address=this.logData[i].id;
this.$http(api_member_ship_department,address)
.then(res => {
//将部门信息加入日志数据
this.logData[i].apr=res;
})
.catch(code => {
this.$message({ type: "error", message: code.message || code });
});
};
大概意思就是从后台循环请求每个人的部门信息,并将其作为apr属性加入现有的对象logData,添加完的logData输出显示是这样的:
然后我再循环输出每个apr的属性值:
for(let i=0;i<this.logData.length;i++){console.log(this.logData[i].apr)}
结果全是undefined,这让我百思不得其解,求大神指点
你取值的过程是异步的,我觉得可能问题是你 循环输出每个apr的属性值 的时候
this.logData[i].apr
其实还没有拿到回调数据