问题：我想把getData(start)中的使用多个 if 这里优化一下，请问如何处理？
```
async getData(start) {

        const _self = this;
        var response = [];
        if(start == 0){
            try {
                // let response = await fetch('mock-data/selectData01.json').then(function(response) {
                //     return response.json(); // 第1个
                // }).then(function(responseThenData) {
                //     //console.log('responseThenData =',responseThenData);
                //     return responseThenData // 第2个
                // }).catch(function(e) {
                //     console.log("Oops, error");
                // });
                response = await fetch('mock-data/selectData01.json').then(function(response) {
                    return response.json();
                })
                return response; // 第3个
            } catch(e) {
                console.log("Oops, error", e);
            }
        } else if (start == 1) {
            try {
                response = await fetch('mock-data/selectData02.json').then(function(response) {
                    return response.json();
                })
                return response; // 第3个
            } catch(e) {
                console.log("Oops, error", e);
            }
        } else if (start == 2) {
            try {

                response = await fetch('mock-data/selectData03.json').then(function(response) {
                    return response.json();
                })
                return response; // 第3个
            } catch(e) {
                console.log("Oops, error", e);
            }
        } else if (start == 3) {
            try {

                response = await fetch('mock-data/selectData04.json').then(function(response) {
                    return response.json();
                })
                return response; // 第3个
            } catch(e) {
                console.log("Oops, error", e);
            }
        } else if (start == 4) {
            try {

                response = await fetch('mock-data/selectData05.json').then(function(response) {
                    return response.json();
                })
                return response; // 第3个
            } catch(e) {
                console.log("Oops, error", e);
            }
        }
    }

    componentDidMount() {
        const _self = this;
        var key = true;


        let dataReadStart = 0;

        _self.getData(dataReadStart)
            .then(function(responseThenData) {
                //console.log('responseThenData =',responseThenData['dataChinaTelecom']['regionData']);
                _self.setState({
                    tableBody: responseThenData['dataChinaTelecom']['emergencyTableData'],
                    tableHead: responseThenData['dataChinaTelecom']['emergencyTableHeader']
                })
            })
            .then(function() {
                //console.log('abc')
            })
            .catch(function(e) {
                console.log("promise, error =", e);
            });


        // var key = true;
        // new Promise(function(resolve, reject){
        //     if(key){
        //         resolve('成功了')
        //     }else{
        //         reject('被拒绝')
        //     }
        // }).then(function(value) {
        //     console.log(value); // key=true 123
        // }, function (rej) {
        //     console.log('---------result reject');
        //     console.log(rej);
        // })

        dataReadStart = dataReadStart + 1;
        setInterval(function(){

            let dataPromise = _self.getData(dataReadStart);
            console.log('dataPromise =',dataPromise)
            dataPromise
                .then(function(responseThenData) {
                    //console.log('responseThenData =',responseThenData['dataChinaTelecom']['regionData']);
                    _self.setState({
                        tableBody: responseThenData['dataChinaTelecom']['emergencyTableData'],
                        tableHead: responseThenData['dataChinaTelecom']['emergencyTableHeader']
                    })
                })
                .then(function() {
                    //console.log('abc')
                })
                .catch(function(e) {
                    console.log("promise, error =", e);
                });
            if(dataReadStart + 1 == 5){
                dataReadStart = 0;
            } else {
                dataReadStart = dataReadStart +1;
            }

        },30000)

        // ECMAScript 定义了 Undefined、Null、Boolean、String、Number、Object 6种类型
        // 其中 Undefined 和 Null 都是只包含一个值得特殊类型，分别为 undefined 和 null
        // 因此根据定义undefined和null分属不同类型
        // 使用===运算符返回false
        // 当声明的变量未初始化时，该变量的默认值是undefined，而null则用于表示尚未存在的对象
    }

```
这里if能不能缩简到一个

回答：```
export default class a {
  async getData(start) {
    var response = [];
    const MAP = [
      { url: 'mock-data/selectData01.json' },
      { url: 'mock-data/selectData02.json' },
      { url: 'mock-data/selectData03.json' },
      { url: 'mock-data/selectData04.json' },
      { url: 'mock-data/selectData05.json' },
    ];
    try {
      response = await fetch(MAP[start].url).then(res => res.json());
      return response;
    } catch (e) {
      console.log('Oops, error', e);
    }
  }
}

```
抛砖引玉

标签: react.js, javascript