我有一个对JSON对象进行了重新编码的对象,以确保FlatList中的项将正确地呈现。我可以阅读我在里面写的所有console.logs,但是没有一个文本出现。知道为什么吗?
以下是代码:
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,但是没有一篇文章
发布于 2018-03-06 05:34:12
您需要将return放在this.singleStore()之前,放在renderItem道具中。
https://stackoverflow.com/questions/49123816
复制相似问题