返回数据后调用函数

时间:2019-03-13 15:50:27

标签: javascript

我想调用一个端点,然后在检索数据时,使用该数据调用一个函数。由于该功能必须可以使用数据!

对不起,如果代码看起来很复杂,那会有些复杂。

我要调用的函数如下:

  potentialEventsData() {
    this.allEngagementTypes().subscribe(data => {
      const products = {};
      data.forEach(product => {
        products[product.id] = product.description;

    this.potentialForEvents(this.organization.id, product.id)
    .subscribe(potentialEventData => {
      console.log('consoling the potential event data' + potentialEventData) <---- this potential event data is what I want to use and parse!
    });
   });
  });
}

因此,我要在下面的函数中解析此potentialEventData: (抱歉,它的功能很大)

我想调用上面的函数,或者只是调用代码,然后当我返回数据时,将potentialEventData解析到该函数中,现在实际上该函数的作用是为每个项目返回一个数组作为其a循环,所以我真的需要先将其连接起来(对不起,刚意识到),然后将该数组发送到this.buildOrganization(updatedGraphTable,resolve)函数作为一个额外的参数,我已经尝试了很多方法来做到这一点,但我还没有设法做到了!

 graph(id: string): Promise<boolean> {

this.organization.setValues(id);
return new Promise((resolve, reject) => {
  if (!this.reload) {
    resolve(false);
  } else {
    let areasLoaded = false;
    let root: IEngagementGraphNode;
    this.getAllProductGroups().then(() => {
      areasLoaded = true;
      this.buildOrganization(root, resolve);
    }).catch(() => {
      areasLoaded = true;
      this.buildOrganization(root, resolve);
    });

    Observable.zip(this.organizationEngagements(id, this.requestOptions()), this.organizationIndividuals(id, this.requestOptions()))
      .subscribe(([graphData, individualsData]) => {
        this.insight.orgsMainName = graphData.name


        if (areasLoaded) {    
          return this.buildOrganization(updatedGraphTable, resolve); <------ here!
        } else {
          root = updatedGraphTable;
        }
      }, error => reject(error));
  }
});
 }

还有buildOrganization函数:

  buildOrganization(root, resolve): void {
    if (root) {
      this.organization.clear();
      this.organization.setProperties(root, this.filterParams);
      this.focus = this.organization;
      if (this.userList.length === 0) {
        this.userList = this.organization.individuals;
      }
      this.reload = false;
      this.data();
      resolve(true);
    }
  }

如果您能提供帮助,那就太好了!谢谢!

0 个答案:

没有答案