Javascript ListView不起作用:";undefined不是对象(正在评估';datasource.row标识';)”;
我试图在我的ListView中查看项目“Pizza”,但我遇到了一个错误。我看了其他一些有同样错误的SO帖子,但我没能找出问题所在。我们应该如何设置我的ListView?我一直在关注这一点以供参考。我的代码如下: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
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”下。我不知道为什么,但我花了相当长的时间来弄清楚:-(
<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}/>