【问题标题】:undefined-is-not-an-object-evaluating-this-state-datasource.mapundefined-is-not-an-object-evaluate-this-state-datasource.map
【发布时间】:2019-05-29 16:27:07
【问题描述】:
componentDidMount(){
    fetch('https://boboboi.online/c_api_sales/get_dest',{
      method: 'POST',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
              },
                body: JSON.stringify({
                        port_code: 'CP-002',
                        api_key: 'ae9a6ce9a7479038d998060ef6d65ca9f86a13ed962a5366b3b0662cc52dde1b',
                        token: 'a959190d43520f8017ed2ca09ffc61bb'
                }),
    })   
        .then((response) => response.json())
        .then((responseJson) => { 
            this.setState({
                isLoading: false,
                dataSource: responseJson
              }, function() {
                // In this block you can do something with new state.
              });
            })
            .catch((error) => {
              console.error(error);
            });
        }

        GetPickerSelectedItemValue=()=>{

            Alert.alert(this.state.PickerValueHolder);

          }

【问题讨论】:

  • 嗨,欢迎 :) 需要记住的几件事,请不要将您的代码作为屏幕截图发布,其次,请提供您的问题和所问内容的完整详细信息。你写问题的方式,没有人能帮助你 - 见这里stackoverflow.com/help/how-to-ask

标签: javascript react-native


【解决方案1】:

map() 方法可以与数组一起使用,但不能与对象一起使用。所以如果你想使用 map 方法,你可以尝试像 Object.keys(this.state.dataSource).map((key, index)=> { //your function and logic });

【讨论】:

  • 喜欢什么?你有我学习的例子或推荐的网站吗?谢谢你
  • 对于您的代码,您可以尝试这样做。 Object.keys(this.state.dataSource).map((key, index) => { console.log(this.state.dataSource[key]); });这将列出您的 json 对象中的所有值。查看此链接developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-19
  • 2020-08-15
  • 2019-03-25
  • 1970-01-01
  • 2020-08-07
  • 2016-04-25
相关资源
最近更新 更多