Realm から返された結果をレンダリングする反応ネイティブな ListView を作成しようとしています。react-native の ListView と Realm の使用方法に関して見つけた指示に従っています。
ただし、常に同じエラーが発生します。Objects are not valid as a React child (found: [object Results]). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of 'Text'.
Realm のドキュメントや他の記事から私が理解していることから、Results オブジェクトは JavaScript リストのように動作することになっているため、cloneWithRows メソッドに受け入れられる必要があります。
誰かが私が間違っていること、またはこれを修正する方法を教えていただければ幸いです。
PS私はreact-nativeのListViewとRealmのListViewの両方を試しましたが、どちらも同じように動作します。
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
Navigator,
TouchableHighlight,
TouchableOpacity,
//ListView,
} from 'react-native';
import { ListView } from 'realm/react-native';
import realm from './myrealm'
class contextview extends Component {
getState() {
console.log("getInitialState");
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
let pictures = [ realm.objects('picture').filtered('new == true') ];
console.log("pictures: " + pictures);
return {
//dataSource: ds.cloneWithRows(['row 1', 'row 2', 'row 3']),
dataSource: ds.cloneWithRows(pictures)
};
}
constructor(props)
{
super(props);
this.state = this.getState();
this.bindMethods();
}
render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData}</Text>}
/>
);
}
}