小编KT.*_*T.C的帖子

获取JSON并迭代react-native中的值

我是新的反应本机,我试图简单地迭代一个示例json文件,但我收到错误undefined不是一个函数(评估'this.state.results.map')

我最初将状态设置为对象,所以不确定为什么我收到此错误.

这是JS:

import React, { Component } from 'react';
import { AppRegistry, ListView, Text, View, StyleSheet, TouchableHighlight } from 'react-native';

var REQUEST_URL = 'https://facebook.github.io/react-native/movies.json';

class WPReact extends Component {
  constructor(props) {
    super(props);
    this.state = {results: []};
  }
  componentDidMount() {
    this.fetchData();
  }
  fetchData() {
    fetch(REQUEST_URL)
      .then((response) => response.json())
      .then((responseData) => {
        this.setState({
          results : { responseData }
        });
      })
      .done();
  }
  render() {
    return this.renderJSON();
  }
  renderJSON() {
    contents = this.state.results.map((item) => {
      <View key={item.movies.title} style={ styles.container }> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

react-native ×1

reactjs ×1