首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >does本机列表页脚组件不工作

does本机列表页脚组件不工作
EN

Stack Overflow用户
提问于 2019-03-25 13:08:14
回答 1查看 2.7K关注 0票数 1

我在研究本土化的反应。我在用FlatList。我想在我下去的时候出示装货杆。这是我写的代码。

我看过文件了,但不起作用。我想我在等待的时候犯了个错误。我不知道怎么用。异步有什么区别?我把代码样本留在下面。

提前谢谢你的帮助。

代码语言:javascript
复制
handleRefresh = () => {
    this.setState({
      offset: 0,
      maxSize: 10,
      isSearch: false,
      isLoading: true,
      isRefreshing: true
    }, () => {
        this.loadData();
    });
};

handleLoadMore = () => {
    this.setState({            
        maxSize: this.state.maxSize + 5,
        isSpinner: true
    }, () => {
        this.loadData();
    });
};

keyExtractor = (item, index) => index.toString();

renderFooter = () => {
    if(this.state.isSpinner === false) { return null; }

    return (
        <View style={{ paddingVertical: 20 }}>
            <ActivityIndicator animating size="small" />
        </View>
    );
};

loadData = async () => {
    try {
        const { offset, maxSize } = this.state;            

        const username = await AsyncStorage.getItem('username');
        const token = await AsyncStorage.getItem('token');

        var credentials = Base64.btoa(username + ':' + token);
        var URL         = `http://demo.espocrm.com/advanced/api/v1/Lead?sortBy=createdAt&asc&offset=${offset}&maxSize=${maxSize}`;            

        axios.get(URL, {headers : { 'Espo-Authorization' : credentials }})
        .then(this.dataSuccess.bind(this))
        .catch(this.dataFail.bind(this));
    } catch (error) {
        Alert.alert(
            'Hata',
            'Bir hata meydana geldi. Lütfen yöneticiye başvurunuz.',
            [
                { text: 'Tamam', onPress: () => null }
            ]
        );
    }
};

dataSuccess(response) {        
    this.setState({ isRefreshing: false, isSpinner: false, isLoading: false, leadList: response.data.list });
}

dataFail(error) {
    this.setState({ isLoading: false });

    Alert.alert(
        'Hata',
        'Beklenmedik bir hata oluştu',
        [
            { text: 'Tamam', onPress: () => null }
        ]
    );
}

render() {
    const { isLoading, isRefreshing, searchText, leadList } = this.state;        
    return(
        <View style={styles.container}>
            <SearchBar 
                placeholder="Bir lead arayın..."
                onChangeText={this.searchLead.bind(this)}
                onClear={this.handleRefresh}
                onCancel={this.loadData}
                value={searchText}
            />
            {
                isLoading ? <ActivityIndicator style={styles.loading} size="large" color="orange" /> :
                        <FlatList
                            data={leadList}
                            ListFooterComponent={this.renderFooter}
                            renderItem={({item}) =>
                                <ListItem
                                    leftAvatar={{ source: { uri: 'https://pbs.twimg.com/profile_images/567081964402790401/p7WTZ0Ef_400x400.png' } }}
                                    title={item.name}
                                    subtitle={item.status}
                                    bottomDivider={true}
                                />
                            }
                            keyExtractor={this.keyExtractor}
                            refreshing={isRefreshing}
                            onRefresh={this.handleRefresh}
                            onEndReached={this.handleLoadMore}
                            onEndReachedThreshold={0.5}
                        />
            }
        </View>
    )
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-25 13:19:43

在FlatList组件中,需要包含一个名为extraData的属性,并将其设置为this.state,这样组件就会更新。

代码语言:javascript
复制
<FlatList
  data={leadList}
  extraData={this.state}
  ...
/>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55338527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档