import React from 'react';
import { View, ListView, ActivityIndicator } from 'react-native';
import { connect } from 'react-redux';
import { ItemOverView } from '../../components/common';
import * as actions from '../../actions';
class AwaitingScreen extends React.Component {
static navigationOptions = {
header: null,
};
state = { loading: true };
componentWillMount() {
this.props.getAwaitingOrders();
this.createDataSource(this.props);
}
componentWillReceiveProps(nextProps) {
this.setState({ loading: false });
this.createDataSource(nextProps);
}
createDataSource({ orders }) {
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
this.dataSource = ds.cloneWithRows(orders);
}
renderListView() {
if (this.state.loading) {
return (<ActivityIndicator
size='large'
color='#397af8'
/>
);
}
return (
<ListView
enableEmptySections
dataSource={this.dataSource}
renderRow={this.renderRow}
/>
);
}
renderRow = (order) => {
return (
<ItemOverView
item={order}
/>
);
}
render() {
return (
<View>
{this.renderListView()}
</View>
);
}
}
const mapStateToProps = state => {
return {
awaitingOrders: state.orders.awaitingOrders,
statusCodes: state.orders.statusCodes
};
};
export default connect(mapStateToProps, actions)(AwaitingScreen);
错误是为了
this.createDataSource(this.props)并没有将它识别为对象,
首先awaitingOrder是一个空数组,然后当我向服务器请求时,我得到一个数组...
例如[{ "product": "productname"}, {"product": "anotherproduct"}]
但由于某种原因我无法呈现列表视图
INITIAL STATE = awaitingOrders: []
当我放this.createDataSource(['hello','hello']);
时
它工作..但我在代码中也找不到任何错误
如果有人帮忙,那将非常有帮助