我对框架相当陌生。 我正在使用React-Native中的dataSource制作基本ListView,并提取数据。React Native cloneWithRows错误 - 对象未定义
constructor(props){
super(props);
var dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
});
this.state = {
searchString: '',
isLoading: false,
message: '',
jsonData: '',
};
}
_fetchData(query){
console.log(query);
this.setState({ isLoading: true });
fetch(query)
.then(response => response.json())
.then(responseData => {
this._handleResponse(responseData);
this.setState({
message: 'seems like it worked!',
dataSource: this.state.dataSource.cloneWithRows(responseData),
});
})
.catch(error =>
this.setState({
isLoading: false,
message: this.state.message + ' --- ' + 'Something bad happened' + error
})
).done();
}
予取的数据是从一个Twitter API响应的提取物:
{ "statuses": [
{
"coordinates": null,
"favorited": false,
"truncated": false,
"created_at": "Mon Sep 24 03:35:21 +0000 2012",
"id_str": "250075927172759552",
"retweet_count": 0,
"in_reply_to_status_id_str": null,
"id": 250075927172759552
}
]}
然而,我得到一个“未定义不是(评价‘dataSource.rowIdentities’)的物体”上cloneWithRows错误。 当我在iOS 8.4和9.1上运行模拟时出现此错误。 我可能错过了一些小小的东西,并且被困了好几个小时。 任何想法?
试过了。我回来'TypeError:无法读取属性'cloneWithRows'的未定义'... –
@EvgenyRoskach我已经更新了我的答案,请检查那将解决您的问题 – Rajeesh
谢谢!有效。 我修改方式如下: this.state = { \t \t \t searchString的: '', \t \t \t isLoading:假, \t \t \t消息: '', \t \t \t的dataSource:新的ListView。数据源({ \t \t \t \t rowHasChanged:(R1,R2)=> R1 == R2, \t \t!}), \t \t \t \t \t}; –