Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native React_native:Error undefined不是函数(计算&x27;data.forEach)ListView错误_React Native - Fatal编程技术网

React native React_native:Error undefined不是函数(计算&x27;data.forEach)ListView错误

React native React_native:Error undefined不是函数(计算&x27;data.forEach)ListView错误,react-native,React Native,我对listview数据源的动态数据分配有问题。 我在构造函数中进行了一个web服务调用,它返回jsonArray,然后在收到后,我将收到的数据(jsonArray)分配给Listview的数据源 `constructor(props){ let data= this.getActivityCalenderList(); const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2, s

我对listview数据源的动态数据分配有问题。 我在构造函数中进行了一个web服务调用,它返回jsonArray,然后在收到后,我将收到的数据(jsonArray)分配给Listview的数据源

  `constructor(props){
  let data= this.getActivityCalenderList();
  const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2,
    sectionHeaderHasChanged: (s1, s2) => s1 !== s2});
  this.state = {
  dataSource: ds.cloneWithRowsAndSections(this.convertArrayToMap(data))}
  }
  }
  render()
  {
   return(
     <ListView  dataSource={this.state.dataSource}
      renderRow={(data) =><View>.....</View>}/>}
     renderSectionHeader={(sectionData, startdatetime)=><View>....</View>}
  );
  }`
`构造函数(道具){
让data=this.getActivityCalenderList();
const ds=新建ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2,
节头更改:(s1,s2)=>s1!==s2});
此.state={
数据源:ds.cloneWithRowsAndSections(this.convertArrayToMap(数据))}
}
}
render()
{
返回(
.....}/>}
renderSectionHeader={(sectionData,startdatetime)=>…}
);
}`
问题是在呈现数据分配Listview之前(静态数据分配正在工作)。
有任何帮助或建议吗?

您可以通过创建DataAcquired状态变量来尝试条件呈现。对componentWillMount进行api调用,并仅在获取数据时显示列表视图。希望这有帮助

constructor(props){
  const ds = new ListView.DataSource({
   rowHasChanged: (r1, r2) => r1 !== r2
  });
  this.state = {
    dataSource: ds.cloneWithRows([]),
    dataObtained: false,
  }
}

componentWillMount (){
    let data = this.getActivityCalenderList();
    this.setState({dataSource: ds.cloneWithRows(data), 
                   dataObtained:true});
}

render()
{
  if(this.state.dataObtained){
    return(
      <ListView  dataSource={this.state.dataSource}
       renderRow={(data) =><View>.....</View>}/>}
       renderSectionHeader={(sectionData, startdatetime)=><View>....
       </View>}
    );
  }else{
    return(
      <View>
        <ActivityIndicator/>
      </View>
    );
  }

}`
构造函数(道具){
const ds=new ListView.DataSource({
行已更改:(r1,r2)=>r1!==r2
});
此.state={
数据源:ds.cloneWithRows([]),
获得的数据:错误,
}
}
组件将安装(){
让data=this.getActivityCalenderList();
this.setState({dataSource:ds.cloneWithRows(data),
获得的数据:真});
}
render()
{
if(此.state.datagovered){
返回(
.....}/>}
renderSectionHeader={(sectionData,startdatetime)=>。。。。
}
);
}否则{
返回(
);
}
}`