2

有屏幕主页和新建。Home 显示存储在 db 中的数据列表。对 db 的新写入。当用户导航到主屏幕但没有显示新数据时,应重新安装主屏幕。这是预期的行为,是否有简单的解决方法?

主屏幕:

class Home extends React.Component {
static navigationOptions = {
    title: 'Home',
};

constructor(props) {
    super(props);

    realm = new Realm({schema: [Case]});
    this.state = {
        cases: realm.objects('Case'),
    }
};

render() {
    const listItems = this.state.cases.map((data, index) =>
        <View style={Styles.listItem}>
            <Text key={index}>
                {data.name}
            </Text>
        </View>
    );
    return (
        <View>
            <ScrollView>
                { listItems }
            </ScrollView>
        </View>
    );
}

路由配置:

const MainScreenNavigator = TabNavigator({
Home: { screen: Home },
New: { screen: NewCase },
});

const SimpleApp = StackNavigator({
    Home: { screen: MainScreenNavigator },
});

AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
4

0 回答 0