我运行react-native链接领域但仍然出错

时间:2017-08-01 14:43:19

标签: javascript ios reactjs react-native realm

我正在测试Realm,并希望让我的简单程序正常运行。我按照所有官方文档(https://realm.io/docs/javascript/latest/#getting-started)开始了,但有些我仍然知道如何error说我需要运行已经完成的react-native link realm

我该如何解决这个问题?

这是index.ios.js档案:

import React, { Component } from 'react';
import {AppRegistry, View} from 'react-native';
import Database from './components/Database';

export default class Realm extends Component {
  render() {
    return (
        <View>
          <Database/>
        </View>
    );
  }
}

AppRegistry.registerComponent('Realm', () => Realm);

这是我的Database.js文件:

import React, { Component } from 'react';
import {Text, View} from 'react-native';
const Realm = require('realm');

class Database extends Component {
    render() {
        let realm = new Realm({
        schema: [{name: 'Dog', properties: {name: 'string'}}]
    });

    realm.write(() => {
    realm.create('Dog', {name: 'Rex'});
});

    return (
    <View>
        <Text>
        Count of Dogs in Realm: {realm.objects('Dog').length}
        </Text>
    </View>
    );
    }
}

export default Database;

1 个答案:

答案 0 :(得分:0)

我认为您现在应该使用 Realm 作为您的主要班级&#39; name,因为它是库名,尝试这个:

import React, { Component } from 'react';
import {AppRegistry, View} from 'react-native';
import Database from './components/Database';

export default class YourApp extends Component {
  render() {
    return (
        <View>
          <Database/>
        </View>
    );
  }
}

AppRegistry.registerComponent('YourApp', () => YourApp);

此外,由于其他代码行是在ES6中编写的,因此在您Database.js中,您可以尝试使用const Realm = require('realm');,而不是使用import Realm from 'realm';

[1, 2, 3, 4, 10, 11, 12, 20, 21, 30, 32, 42, 43, 44, 45, 48, 49]
|> Enum.reverse()
|> Enum.reduce([], fn
  x, [head = [h | _] | tail] when x == h - 1 -> [[x | head] | tail]
  x, acc -> [[x] | acc]
end)
|> IO.inspect(charlists: :as_integers)

如果问题仍然存在,那么您可能需要链接“领域”。手动库(也可以在您提供的链接中找到)