【发布时间】:2018-04-06 05:57:25
【问题描述】:
我有一个小问题.. 我依赖于 2 个服务,我循环所有组织,对于每个组织,我循环连接到组织的系统,将每个系统推送到一个对象。这很好用,在这里没问题......当我创建我的地图时出现问题,因为此时,this.systemList 对象是空的......所以我只希望在我完成后调用我的 createMap() 函数将所有项目添加到数组(this.systemList)
所以我想以某种方式检查是否所有组织和所有系统都完成了循环,并且所有系统都已添加到:this.systemList 数组,首先在这里调用this.createMap()
希望它有意义吗?
在此处查看代码:
methods: {
getSystemsForOrganization(orgId) {
SystemService.getSystemsForOrganization(orgId).then((response) => {
let systems = response.data.systems;
let systemPromises = [];
if(systems) {
systems.forEach((system, index, array) => {
let systemHasAlarms = !!system.pending_events;
let systemObject = {
id: system.id,
name: system.name,
latitude: system.latitude,
longitude: system.longitude,
latlng: [system.latitude, system.longitude],
has_alarms: systemHasAlarms
};
this.systemList.push(systemObject);
});
}
});
},
getCurrentOrganizations() {
OrganizationService.getOrganizationData().then((response) => {
let organizations = response.data.organizations;
let organizationsIds = organizations.map((org) => {
return org.id;
});
organizationsIds.forEach((id, index, array) => {
this.getSystemsForOrganization(id);
});
});
},
},
mounted() {
this.getCurrentOrganizations();
this.createMap();
}
【问题讨论】:
标签: javascript ecmascript-6 vue.js vuejs2