我對React-Native很新。遵循基本的React-Native教程,我試圖從「https://facebook.github.io/react-native/movies.json」中獲取JSON數據。我可以顯示title
和description
性能,但是當我嘗試使用ListView
我收到以下錯誤顯示「電影」屬性:未定義不是一個對象(評估'allRowsIDs.length')(React-Native)
undefined is not an object (evaluating 'allRowsIDs.length')
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
ListView
} from 'react-native';
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
export default class AwesomeProject extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: 'init',
};
}
componentWillMount() {
fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
this.setState({ dataSource: ds.cloneWithRows(responseJson.movies) });
})
.catch((error) => {
console.error(error);
});
}
render() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData}</Text>}
/>
</View>
);
}
}
非常感謝你,那工作! – rnboi05
然後,您應該將其標記爲正確;-) –