【发布时间】:2016-04-07 10:04:26
【问题描述】:
代码是这样的-
loadData: function(){
var _this = this;
this.API();
//check if data is loaded
setTimeout(function(){
if(_this.isMounted()){
if(_this.state.loaded===false){
_this.setState({
isReloadRequired: true
})
}
}
}, 10000);
},
API: function(){
var _this = this;
this.setState({ rawData: [], isReloadRequired: false, loaded: false, isRefreshing: true });
Parse.Cloud.run('fetchBookingListForUserCloudFunction', {
user_id: Parse.User.current().getUsername()
}).then(
function(result){
var cleanData = [];
for(var i=0;i<result.length;i++){
cleanData.push(result[i].toJSON());
}
_this.setState({
rawData: _this.state.rawData.concat(cleanData),
dataSource: _this.state.dataSource.cloneWithRows(cleanData),
loaded: true,
isReloadRequired: false,
isRefreshing: false,
});
},
function(error){
_this.setState({ isReloadRequired: true, loaded: false, isRefreshing: false })
console.log("[HOME API] Error: "+ JSON.stringify(error, null, 2));
}
);
},
render: function(){
return(
{this.state.loaded ? this.renderListView() : this.renderLoadingView()}
)
},
renderListView: function(){
if(this.state.rawData.length === 0){
return(
<View style={styles.container}>
<Text>Tap to book.</Text>
</View>
);
}
return(
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderReservation}
style={styles.listView}
refreshControl={
<RefreshControl
refreshing={this.state.isRefreshing}
onRefresh={this.loadData}
/>
}
/>
);
},
renderLoadingView: function(){
return(
<View style={styles.container}>
<LoadingView />
</View>
)
},
出了什么问题?我也无法在 github 上找到任何东西。 出了什么问题?我在 github 上也找不到任何东西。
更新
嗨。感谢您在 rnplay 上创建示例。但我已将问题的原因缩小到这个范围 - 每当我在 render() 中使用 RefreshControl 和 ListView 时,它都会按预期工作。但是,当我从renderlistView() 等其他函数返回ListView 和RefreshControl 时,它会引发上述错误。我什至尝试过this.loadData().bind(this),但这也无济于事。
【问题讨论】:
-
这个问题在 3 天前得到修复。看到这个 git 提交:github.com/facebook/react-native/commit/…
标签: reactjs react-native react-native-listview react-native-scrollview