Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Javascript ListView不起作用:";undefined不是对象(正在评估';datasource.row标识';)”;_Javascript_Android_Ios_Listview_React Native - Fatal编程技术网

Javascript ListView不起作用:";undefined不是对象(正在评估';datasource.row标识';)”;

Javascript ListView不起作用:";undefined不是对象(正在评估';datasource.row标识';)”;,javascript,android,ios,listview,react-native,Javascript,Android,Ios,Listview,React Native,我试图在我的ListView中查看项目“Pizza”,但我遇到了一个错误。我看了其他一些有同样错误的SO帖子,但我没能找出问题所在。我们应该如何设置我的ListView?我一直在关注这一点以供参考。我的代码如下: class MyNewAppreactold extends Component { constructor(props) { super(props); this.state = { dataSource: new ListView.DataSour

我试图在我的ListView中查看项目“Pizza”,但我遇到了一个错误。我看了其他一些有同样错误的SO帖子,但我没能找出问题所在。我们应该如何设置我的ListView?我一直在关注这一点以供参考。我的代码如下:

class MyNewAppreactold extends Component {

  constructor(props) {
    super(props);
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      })
    };
  }


  componentDidMount() {
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows([{ title: 'Pizza' }])
    })
  }

  _renderItem(item) {
    return (
      <ListItem item={item} />
      // <ListItem item={item} onPress={onPress} />
      // <ListItem item={item} onPress={() ==""> {}} />
    );
  }

  render() {
    return (
      <View style={styles.container}>

        <StatusBar title="Grocery List" />

        <ListView datasource={this.state.dataSource}
          renderrow={this._renderItem.bind(this)}
          style={styles.listview}/>

        <ActionButton title="Add" />

      </View>
    )
  }
}

AppRegistry.registerComponent('MyNewAppreactold', () => MyNewAppreactold);
类MyNewAppreacted扩展组件{
建造师(道具){
超级(道具);
此.state={
数据源:新建ListView.dataSource({
行已更改:(行1,行2)=>行1!==行2,
})
};
}
componentDidMount(){
这是我的国家({
dataSource:this.state.dataSource.cloneWithRows([{title:'Pizza'}]))
})
}
_renderItem(项目){
返回(
// 
//  {}} />
);
}
render(){
返回(
)
}
}
AppRegistry.registerComponent('MyNewAppreacted',()=>MyNewAppreacted);

您是否尝试更改为
数据源

<ListView 
     dataSource={this.state.dataSource}
     renderRow={(rowData) => <ListItem item={rowData} />}
/> 
}
/> 


然后

renderRow(rowData) { 
    return (
        <ListItem item={item} />
    ); 
}
renderRow(行数据){
返回(
); 
}

如果有人偶然发现这个问题

  • ListView的“cloneWithRows”绑定在“componentDidMount”中不起作用。您需要将其推到“componentWillMount”下。我不知道为什么,但我花了相当长的时间来弄清楚:-(

请使用正确的道具名称: 将dataSource更改为dataSource,将renderrow更改为renderrow

这样代码就可以正常工作了

 <ListView dataSource={this.state.dataSource}
      renderRow={this._renderItem.bind(this)}
      style={styles.listview}/>


你能在你的代码中创建这样的renderRow并检查你是否在使用renderRow,它是全小写的。你能像上面和下面那样尝试吗check@SivajeeBattina我试过renderRow,但仍然出现同样的错误。
 <ListView dataSource={this.state.dataSource}
      renderRow={this._renderItem.bind(this)}
      style={styles.listview}/>