Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下拉加载更多,数据多的话拼命“玩命加载中”文字过来好一会儿才出现 #32

Open
qingjiaowochengzd opened this issue Jul 14, 2018 · 1 comment

Comments

@qingjiaowochengzd
Copy link

qingjiaowochengzd commented Jul 14, 2018

<View style={{flex: 1}}>
            <RefreshListView
                data={this.state.goodlist}
                keyExtractor={this.keyExtractor}
                renderItem={this.renderCell}
                refreshState={this.state.refreshState}
                onHeaderRefresh={this.onHeaderRefresh.bind()}
                onFooterRefresh={this.onFooterRefresh.bind()}

                // 可选
                footerRefreshingText= '玩命加载中 >.<'
                footerFailureText = '我擦嘞,居然失败了 =.=!'
                footerNoMoreDataText= '-我是有底线的-'
                footerEmptyDataText= '-好像什么东西都没有-'
            />
</View>


onHeaderRefresh = () => {
        // 下拉刷新
        this.setState({refreshState: RefreshState.HeaderRefreshing}, () => {
            this.getGoods(true, {offset: 0})
        })
    }
    onFooterRefresh = () => {
        // 上拉加载
        this.setState({refreshState: RefreshState.FooterRefreshing}, () => {
            const params = {
                offset: this.state.offset + 10,
            }
            this.getGoods(false, params)
        })
        
    }


getGoods = (isReload, params) => {
        let reqparams = {
            systemBookCode: "4344",
            department: "",
            categoryCode: "",
            offset: this.state.offset,
            limit: this.state.limit,
            sortField: "item_code",
            sortBy: "asc"
        }
        if (params) {
            reqparams = {
                ...reqparams,
                ...params,
            }
        }
        if (isReload) {
            // 下拉刷新出前10条数据
            console.log('前10条数据查询条件', reqparams)
            postJSON(getgoodUrl, reqparams, (res) => {
                console.log(res)
                if (res.code === 0) {
                    if (res.data && res.data.length > 0) {
                        this.setState({
                            // ...params,
                            goodlist: res.data,
                            offset: 0,
                            refreshState: res.data.length < 1 ? RefreshState.EmptyData : RefreshState.Idle,
                        });
                    } else {
                        this.setState({
                            goodlist: [],
                            refreshState: RefreshState.EmptyData
                        })
                    }
                } else {
                    this.setState({
                        refreshState: RefreshState.Failure
                    })
                }
            })
        } else {
            // this.setState({refreshState: RefreshState.HeaderRefreshing})
            // 上拉加载更多
            console.log('false请求参数', reqparams)
            postJSON(getgoodUrl, reqparams, (res) => {
                if (res.code === 0) {
                    if (res.data.length > 0) {
                        let newdatalist = this.state.goodlist.concat(res.data)
                        this.setState({
                            // ...params,
                            goodlist: newdatalist,
                            offset: reqparams.offset,
                            refreshState: res.data.length < 1 ? RefreshState.EmptyData : RefreshState.Idle,
                        });
                    } else {
                        this.setState({
                            refreshState: res.data.length < 1 ? RefreshState.NoMoreData : RefreshState.Idle,
                        });
                    }
                } else {
                    this.setState({
                        refreshState: RefreshState.Failure
                    })
                }
            })
        }
    }
@xvbo
Copy link

xvbo commented Nov 9, 2018

我有同样的问题 请问解决了么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants