Javascript 无法修改域+;中写入事务错误之外的托管对象;自然反应
我试图在Realm中为我的数据库编写一个类,并以本机方式进行响应,我确定出了什么问题。我的领域代码如下。当我在Topic Manager类上调用createTopic方法时,我收到一条错误消息“无法修改写入事务之外的托管对象”。屏幕上显示红色。写入数据库的方法在…之前正在工作。。。。所以我一定错过了一些简单的东西。谢谢你看Javascript 无法修改域+;中写入事务错误之外的托管对象;自然反应,javascript,react-native,mobile,realm,realm-mobile-platform,Javascript,React Native,Mobile,Realm,Realm Mobile Platform,我试图在Realm中为我的数据库编写一个类,并以本机方式进行响应,我确定出了什么问题。我的领域代码如下。当我在Topic Manager类上调用createTopic方法时,我收到一条错误消息“无法修改写入事务之外的托管对象”。屏幕上显示红色。写入数据库的方法在…之前正在工作。。。。所以我一定错过了一些简单的东西。谢谢你看 import React, { Component } from 'react'; const Realm = require('realm'); class Topic
import React, { Component } from 'react';
const Realm = require('realm');
class Topic {}
Topic.schema = {
name: 'Topic',
primaryKey: 'key',
properties: {
name: 'string',
key: 'string'
},
};
const topicManager = new Realm({schema: [Topic]});
export class TopicManager {
constructor(props) {
}
createTopic(insertName) {
const uuid = this.uuidv4();
savedTopic = topicManager.create('Topic', {
key: uuid,
name: insertName,
});
}
uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
}
大概
createTopic(insertName) {
topicManager.write(() => { // <--
savedTopic = topicManager.create('Topic', {
key: uuid,
name: insertName,
});
}); // <--
}
createTopic(插入名称){
topicManager.write(()=>{//谢谢!不应该错过那一个哈哈