Javascript 试图使用现有主键值创建类型为的对象';未实施';

Javascript 试图使用现有主键值创建类型为的对象';未实施';,javascript,reactjs,react-native,realm,Javascript,Reactjs,React Native,Realm,每当用户点击Submit时,我都试图将用户电子邮件地址存储在领域中,但每当我这样做时,我都会收到错误(下面的链接)。我知道数据一直存在于域中,每次渲染时,我都试图创建一个同名的新电子邮件对象 我跟着(更新部分)。也许更新可以解决这个问题realm.write()方法是我关注的重点 这是我的.js文件: import React, { Component } from 'react'; import {TextInput, KeyboardAvoidingView, Text, StyleShe

每当用户点击
Submit
时,我都试图将用户电子邮件地址存储在
领域
中,但每当我这样做时,我都会收到错误(下面的链接)。我知道数据一直存在于域中,每次渲染时,我都试图创建一个同名的新电子邮件对象

我跟着(更新部分)。也许更新可以解决这个问题
realm.write()
方法是我关注的重点

这是我的
.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;
import React,{Component}来自'React';
从“react native”导入{TextInput,KeyboardAvoidingView,Text,StyleSheet,TouchableOpacity};
从“/Third”导入第三个;
第二类扩展组件{
onButtonPress(){
这个是.props.navigator.push({
id:'Third'/.js文件名
});
}
render(){
const Realm=require('Realm');
类电子邮件{}
Email.schema={
名称:'电子邮件',
primaryKey:'名称',
特性:{
名称:“字符串”,
},
};
const realm=新领域({schema:[Email]});
//质疑
让email=realm.objects('email');
//email.length/=>0
//写
realm.write(()=>{
email=realm.create('email'{
名字:“某物”
});
create('Email',{name:“else”},true);
});
返回(
提交
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
填充:20//使按钮水平方向更长。
},
用户输入:{
marginBottom:20,
身高:40,
边框宽度:4
},
用户输入:{
marginBottom:20,
背景颜色:“#9b42f4”,
身高:40,
边界半径:10,
边框宽度:1
},
按钮容器:{
背景颜色:“#41bbf4”,
填充垂直:10,
marginBottom:20,
边界半径:10
},
按钮文字:{
textAlign:'中心',
颜色:“#FFFFFF”
}
});
第二,出口违约;
第二个
域.create()
正在更新将
else
作为主键值的对象。第二个
域.create()
正在更新将
else
作为主键值的对象。