【发布时间】:2015-10-26 00:32:14
【问题描述】:
我对框架很陌生。 我正在使用 React-Native 中的 dataSource 制作一个基本的 ListView,其中包含我获取的数据。
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
}
]}
然而,我在 cloneWithRows 上收到“未定义不是对象(评估 'dataSource.rowIdentities')”错误。 当我在 iOS 8.4 和 9.1 上运行模拟时出现此错误。 我可能错过了一些小东西,并且已经被困了几个小时。 有什么想法吗?
【问题讨论】:
标签: ios node.js react-native