为了账号安全,请及时绑定邮箱和手机立即绑定

this._fetchData(page) is not a function?

this._fetchData(page) is not a function?

牛魔王的故事 2019-03-14 18:15:35
我在加载更多数据_fetchMoreData()的时候重新调用this._fetchData(),为什么这里会报‘this._fetchData() is not a function()’componentDidMount(){    this._fetchData(1)}//请求数据_fetchData(page) {    const that = this    //如果页数不为零,则修改上滑isLoadingData的state为true;    //否则就修改下拉刷新isRefreshing的state为true    if(page !== 0){        this.setState({            isLoadingData: true        })    }else{        this.setState({            isRefreshing: true        })    }     try {        //request.get('http://www.rapapi.org/mockjs/33254/api/list?accessToken=labike&page=10')        request.get(Config.api.baseUrl + Config.api.list, {            accessToken: 'labike',            page: page        }) }_fetchMoreData(){    // if(!this._hasMoreData || this.state.isLoadingData){    //     return    // }    const page = cacleResult.nextPage    console.log(page)    this._fetchData(page)}render(){    return(        <View style={styles.container}>            <View style={styles.header}>                <Text style={styles.headerTitle}>Header</Text>            </View>            <ListView                dataSource={this.state.dataSource}                renderRow={this._renderItem}                renderFooter={this._renderFooter}                refreshControl={                    <RefreshControl                        refreshing={this.state.isRefreshing}                        onRefresh={this._onRefresh}                        tintColor="#ff0000"                        title="Loading..."                    />                }                onEndReached={this._fetchMoreData}                onEndReachedThreshold={20}                showsVerticalScrollIndicator={false}                enableEmptySections={true}            />        </View>    )}
查看完整描述

1 回答

?
心有法竹

TA贡献1866条经验 获得超5个赞

this作用域的问题,把_fetchMoreData改成箭头函数


查看完整回答
反对 回复 2019-03-28
  • 1 回答
  • 0 关注
  • 331 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号