Tôi rất mới đối với React-Native. Theo hướng dẫn React-Native cơ bản, tôi đang cố gắng lấy dữ liệu JSON từ "https://facebook.github.io/react-native/movies.json". Tôi có thể hiển thị title
và description
tính nhưng khi tôi cố gắng để hiển thị "phim" sở hữu sử dụng một ListView
tôi nhận được lỗi sau:undefined không phải là một đối tượng (đánh giá '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>
);
}
}
Cảm ơn bạn rất nhiều, đã làm việc! – rnboi05
Sau đó, bạn có lẽ nên đánh dấu nó là đúng ;-) –