首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FlatList renderItem正在触发,console.logs是可见的,但文本不是。短信怎么了?

FlatList renderItem正在触发,console.logs是可见的,但文本不是。短信怎么了?
EN

Stack Overflow用户
提问于 2018-03-06 05:16:01
回答 1查看 2K关注 0票数 0

我有一个对JSON对象进行了重新编码的对象,以确保FlatList中的项将正确地呈现。我可以阅读我在里面写的所有console.logs,但是没有一个文本出现。知道为什么吗?

以下是代码:

代码语言:javascript
复制
import { 
        View,
        FlatList,
        Text,
        TouchableWithoutFeedback,
        AsyncStorage,
        ScrollView,
        Picker

        } from 'react-native'

import { NavigationActions } from 'react-navigation';
import { Header, Card, CardSection, Button, Input } from '../common';
import Config from '../Config';

export default class CustomStore extends Component {
    constructor(props) {
        super(props);
        this.state = {
            stores: [],
            forceRedraw: false
        };
    }

    static defaultProps = {
        //stores:[{"place": "youngja", "id": "1"},{"place": "tasty", "id": "2"}]
    };

    componentWillMount() {
        const newJSON = {"gym":{"id":"1", "day": "Sunday"}, "restaurant":{"id": "2", "day": "Monday"}};
            const JSArr = Object.values(newJSON);
            //console.log(JSArr);
            this.setState({
                stores: JSArr
            });
    }
    deleteEntry() {
        console.log('this is working')   
    }
    renderListOfStores() {
        return <FlatList
                    data={this.state.stores}
                    renderItem={ (item) => {
                        console.log('here is your thing',item);
                        this.singleStore(item)}
                    }
                    keyExtractor={(item) => item.id}        
                />;
    }

    singleStore(item) {
        return <View>
            {console.log('inside the singleStore method')}
                    <Card>
                        <Text>hello{console.log('this is inside the text tag')}{item.day}</Text>
                        <Button
                                onPress={() => this.deleteEntry()}
                            >
                                <Text>Press this to delete this entry</Text>
                        </Button>
                    </Card>
            </View>;
    }
    render() {

        return(
            <ScrollView> 
                <Header headerText="Custom Store Screen"/>
                <Text>This should be a list of stores</Text>
                {this.renderListOfStores()}
                <Text>This is the end of the list</Text>
            </ScrollView>
        )
    }
}

正如您所看到的,我已经将console.logs放在renderListOfStores方法中,以验证它是否被触发。我有另一个console.log在singleStore method..this控制台日志中,visible..as也是标记中的最后一个控制台日志。我不知道为什么我能读到console.logs,但是没有一篇文章

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-06 05:34:12

您需要将return放在this.singleStore()之前,放在renderItem道具中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49123816

复制
相关文章

相似问题

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