React Native中.map功能的奇怪性能问题

时间:2019-05-04 13:28:13

标签: javascript react-native

我的后端API仅从数据库返回4-5条记录,并且我正在使用.map函数来遍历它们中的每一个,以通过React Native显示。显示此数据的性能非常慢,对此我会寻求您的帮助。

API

app.post('/getBreedsWithoutToken', function (req, res) {
    var obj = req.body;
    let response = {};
    console.log("/getBreedsWithoutToken"+ obj.x + new Date());
    let sql = "select breedID,breedName from subModulesBreeds  where status>0 order by breedName limit 0,5";
    //console.log(sql);
    db.query(sql, function (err, row) {
      if (row) {
        response.code = "S";
        response.alert = "OFF";
        response.alertMessage = "SUCCESS";
        response.data = row;
        res.json(response);
      } else {
        response.code = "E";
        response.alert = "ON";
        response.alertMessage = "Error - Unable to find your details. Please try again";
        response.data = "";
        res.json(response);
      }
      });
  });

在React Native中获取

 fetch('http://localhost:3001/getBreedsWithoutToken',{
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(obj),
    })
    .then(res => res.json())
    .then(json => {
      console.log('json:', json)
      dispatch(getPeopleSuccess(json.data))
    })
    .catch(err => dispatch(getPeopleFailure(err)))

.map函数

{
             people.length? (
              people.map((person,index) => 
                  <View key={index}>
                    <Text>Name: {person.breedName}</Text>

                  </View>
              )
              ) : null
}

0 个答案:

没有答案