我该如何启动Realm?

时间:2017-07-31 19:20:34

标签: javascript reactjs react-native realm

https://github.com/realm/realm-browser-osx

我在上面的git clone上运行了GitHub,所以它在我的项目目录中。

我从Realm Browser下载了App Store应用,但现在我尝试在我的React Native项目中使用它。在GitHub页面(上方)上,它显示Realm Browser is a small utility for Mac OS X that lets you open .realm files to view and modify their contents

有哪些.realm个文件可以打开?我要放入Realm的商品不在.realm个文件中,而是放在我的.js文件中。我该如何解决这个问题?

这是我的.js文件:

import React, { Component } from 'react';
import {TextInput, KeyboardAvoidingView, Text, StyleSheet, TouchableOpacity} from 'react-native';
import Third from './Third';

class Second extends Component {
    onButtonPress() {
        this.props.navigator.push({
            id: 'Third' // .js file name
        });
    }

    render() {
        const Realm = require('realm');

        class Email {}
        Email.schema = {
            name: 'Email',
            primaryKey: 'name',
            properties: {
                name: 'string',
            },
        };

        const realm = new Realm({schema: [Email]});

// Query
        let email = realm.objects('Email');
        // email.length // => 0

// Write
        realm.write(() => {
            email = realm.create('Email', {
                name: 'something'
            });

            realm.create('Email', {name: "else"}, true);
        });

        return(
            <KeyboardAvoidingView style={styles.container}>

                <TextInput
                    style={styles.userInput}
                    placeholder={" email"}
                />

                <TextInput
                    style={styles.userInput}
                    placeholder={" password"}
                    secureTextEntry={true}
                />

                <TouchableOpacity style={styles.buttonContainer}>
                    <Text onPress={this.onButtonPress.bind(this)} style={styles.buttonText}>Submit</Text>
                </TouchableOpacity>

            </KeyboardAvoidingView>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        padding: 20 // makes button horizontally longer.
    },

    userInput: {
        marginBottom: 20,
        height: 40,
        borderWidth: 4

    },

    userInput: {
        marginBottom: 20,
        backgroundColor: '#9b42f4',
        height: 40,
        borderRadius: 10,
        borderWidth: 1
    },

    buttonContainer: {
        backgroundColor: '#41bbf4',
        paddingVertical: 10,
        marginBottom: 20,
        borderRadius: 10
    },

    buttonText: {
        textAlign: 'center',
        color: '#FFFFFF'
    }
});

export default Second;

0 个答案:

没有答案