drjltlm156790 2019-07-08 22:48
浏览 85

如何使用fetch在native native中显示列表?

The data i sent it from fetch and php , it's can be load and the result of the flat liste is none and it was only the text i wrote also i use flatliste but nothing in on the screen , i think the problem is in array sat and how to use value , key and item

import ajax from './fetchdata.js'
export class Home extends Component {
  constructor(props) {
      super(props);
      this.state = { sat: [] };
  }

  async componentDidMount() {
   const sat = await ajax.fetchset();
   console.log(this.state.sat);
   this.setState({sat});
  }

  render() {
    return (
          <View style={styles.container}>
            <Text style={styles.h2text}>
              Black Order
            </Text>
           <FlatList
                data={this.state.sat}
                keyExtractor={item => item.idC}
                renderItem={ ({item}) => {
                        return (
                                    <View style={{ flex : 1, flexDirection : "row" }}>
                                    <View style={{ flex : .6 }}>
                                        <Text style={{ fontSize : 20 , textColor:'red'}}>{item.nom}</Text>
                                    </View>
                                    <View style={{ flex : .4 }}>
                                            <Text style={{ fontSize : 20 , textColor:'red' }}>{item.adresse} points</Text>
                                    </View>
                                      </View>
                              );
                        }

                      }

                       />

          </View>
    );
  }
}
*/




export default Home;



////////fetchdata.js

 export default {
    async fetchset() {
        try {
                let response = await fetch('http://localhost/APP/Chauffeur/Backendapp/api/Traitement/AffichageStation.php');
                let responseJsonData = await response.json();
                console.log("done")
                return responseJsonData;

            }
        catch(e) {
            console.log(e)
        }
    }
}

exepected a liste of data the adresse and nom , but the message is only the the text Black Order

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug