Javascript 如何在React.js的处理函数中调用Promise.all

Javascript 如何在React.js的处理函数中调用Promise.all,javascript,reactjs,es6-promise,Javascript,Reactjs,Es6 Promise,我有两个API调用,我正试图根据输入进行调用 api.js import axios from 'axios'; export const getWeather = input => { }; export const getForecast = input => { }; 在我的React组件中: import React, { Component } from 'react'; import WeatherDisplay from './WeatherDisplay'; i

我有两个API调用,我正试图根据输入进行调用

api.js

import axios from 'axios';

export const getWeather = input => {
};

export const getForecast = input => {
};
在我的React组件中:

import React, { Component } from 'react';
import WeatherDisplay from './WeatherDisplay';
import * as api from '../utils/api';
import dataTracker from '../utils/dataTracker';

import '../scss/app.scss';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      input: '',
      weatherFromInput: null,
    };
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  componentDidMount() {
    console.dir(dataTracker);
  }

  handleChange(event) {
    this.setState({
      input: event.target.value,
    });
  }

  // prettier-ignore
  handleSubmit(event) {
    event.preventDefault();
    var promises = Promise.all(api.getWeather(this.state.input), api.getForecast(this.state.input))

    promises.then(function(input) {
      this.setState({ weatherFromInput: input[0], input: '' });
      console.log("input", input[0]);
    }.bind(this));
  }

  render() {
    return (
      <div className="container">
        <div className="container">
          <form name="weatherApp" onSubmit={this.handleSubmit}>
            <h2>Open Weather App</h2>
            <div className="row">
              <div className="one-half column">
                <label htmlFor="insertMode">Insert your location</label>
                <input
                  name="zipcode"
                  className="u-full-width"
                  placeholder="please enter city or zipcode"
                  type="text"
                  autoComplete="off"
                  value={this.state.input}
                  onChange={this.handleChange}
                />
              </div>
              <div className="one-half column">
                <label htmlFor="showMin">show minimum</label>
                <input type="checkbox" />
                <label htmlFor="showMax">show maximum</label>
                <input type="checkbox" />
                <label htmlFor="showMean">show mean</label>
                <input type="checkbox" />
              </div>
            </div>
            <div className="row">
              <div className="two-half column">
                <input type="submit" value="Submit" />
              </div>
            </div>
          </form>
        </div>

        <div className="container">
          <div className="row">
            <div className="twelve columns">
              {this.state.weatherFromInput !== null ? <WeatherDisplay weather={this.state.weatherFromInput} /> : null}
            </div>
          </div>
        </div>
      </div>
    );
  }
}

任何帮助都将不胜感激

我相信
Promise.all()
需要一个数组,所以:

var promises = Promise.all(api.getWeather(this.state.input), api.getForecast(this.state.input))
应该是

var promises = Promise.all([api.getWeather(this.state.input), api.getForecast(this.state.input)])

哪一条是77号线?什么是未定义的
handleSubmit
如何命名?@FelixKling的观点很好。我所拥有的非常稀少。我更新了问题!不保证。所有人都期望一个数组?这样的参数列表行吗?谢谢伙计!就这样!
var promises = Promise.all([api.getWeather(this.state.input), api.getForecast(this.state.input)])