嗨,我是新生的做出反应。
在我的componentDidMount()
方法中,我有两个获取请求
每个获取请求都会给出json
响应。我想使用新的json
响应更新视图。
我试过但我不断收到错误:
undefined is not an object (evaluating 'allRowIDs.length') ListView_render D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Lists\ListView\ListView.js:391:52 <unknown> D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:1231:14 measureLifeCyclePerf D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:63:11 _renderValidatedComponentWithoutOwnerOrContext D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:1231:8 _renderValidatedComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:1262:26 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:517:24 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 mountChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactMultiChild.js:280:10 initializeChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:68:41 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:174:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:534:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 mountChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactMultiChild.js:280:10 initializeChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:68:41 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:174:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:534:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 mountChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactMultiChild.js:280:10 initializeChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:68:41 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:174:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:534:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:534:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 mountChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactMultiChild.js:280:10 initializeChildren D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:68:41 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\native\ReactNativeBaseComponent.js:174:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:534:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 performInitialMount D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:534:6 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:365:8 mountComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:57:6 _updateRenderedComponentWithNextElement D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:1178:8 _updateRenderedComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:1124:6 _performComponentUpdate D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:1055:36 updateComponent D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:940:8 performUpdateIfNecessary D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactCompositeComponent.js:794:8 performUpdateIfNecessary D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactReconciler.js:210:46 runBatchedUpdates D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactUpdates.js:146:6 perform D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\Transaction.js:152:24 perform D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\Transaction.js:152:24 perform D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactUpdates.js:78:6 flushBatchedUpdates D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactUpdates.js:164:24 closeAll D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\Transaction.js:223:29 perform D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\Transaction.js:165:24 batchedUpdates D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactDefaultBatchingStrategy.js:61:33 enqueueUpdate D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactUpdates.js:183:36 enqueueUpdate D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactUpdateQueue.js:33:29 enqueueSetState D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Renderer\src\renderers\shared\stack\reconciler\ReactUpdateQueue.js:246:18 setState D:\MobileApps\ticketApp12\node_modules\react\cjs\react.development.js:167:31 <unknown> D:\MobileApps\ticketApp12\app\dashboardComponent\TicketDetails.js:60:22 tryCallOne D:\MobileApps\ticketApp12\node_modules\promise\setimmediate\core.js:37:14 <unknown> D:\MobileApps\ticketApp12\node_modules\promise\setimmediate\core.js:123:25 <unknown> D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:117:50 callTimer D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Core\Timers\JSTimersExecution.js:95:8 callImmediatesPass D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Core\Timers\JSTimersExecution.js:199:36 callImmediates D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\Core\Timers\JSTimersExecution.js:214:11 <unknown> D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:223:23 __guard D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:213:6 __callImmediates D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:223:17 <unknown> D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:102:6 __guard D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:213:6 callFunctionReturnFlushedQueue D:\MobileApps\ticketApp12\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:100:17
这是我的代码
const SideMenu = require('react-native-side-menu');
const Menu = require('./Menu');
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View, Image, TextInput, ListView, ActivityIndicator, TouchableOpacity, ScrollView } from 'react-native';
import { Navigator } from 'react-native-deprecated-custom-components'
import authController from '../authController/auth'
import frequentData from '../frequentData/frequentData'
import cannedResponseController from '../cannedResponseComponent/cannedResponse'
const platForm = require('react-native').Platform.OS;
export default class TicketDetails extends Component {
constructor(props) {
super(props);
this.state = {data : [], isLoading: true, tikid : '113',
isOpen: false,
selectedItem: 'About',};
}
toggle() {
this.setState({
isOpen: !this.state.isOpen,
});
}
updateMenuState(isOpen) {
this.setState({ isOpen, });
}
onMenuItemSelected = (item) => {
frequentData.setSelectedItem(item);
this.setState({
isOpen: false,
selectedItem: item,
});
const refernce = this;
refernce.navigate('tickets');
console.log("Selected Item : "+ item);
}
componentDidMount() {
// get Ticket details
console.log("Ticket Details for Ticket Id : "+ frequentData.getSelectedticketId().toString());
return fetch('https://user-api.zupportdesk.com/api/Ticket/GetTicket?TicketID='+ frequentData.getSelectedticketId().toString(), {
method: 'GET',
headers: {
'Content-Type':'application/json; charset=utf-8',
'Accept':'application/json, text/plain, */*',
'Authorization': 'Bearer '+ frequentData.thirdjsoncalltoken,
},
})
.then((response) => response.json())
.then((responseJson) => {
console.log("Tick id to Display : "+ responseJson.ReturnObj.TicketID);
this.setState({
isLoading: false,
tikid : responseJson.ReturnObj.TicketID,
dataSource:'nodata',
}, function() {
// do something with new state
});
})
.catch((error) => {
console.error(error);
});
console.log("Selected Ticket id to get data : "+ frequentData.getSelectedticketId().toString());
return fetch('https://user-api.zupportdesk.com/api/Ticket/GetTicketHistory?TicketID='+ frequentData.getSelectedticketId().toString(), {
method: 'GET',
headers: {
'Content-Type':'application/json; charset=utf-8',
'Accept':'application/json, text/plain, */*',
'Authorization': 'Bearer '+ frequentData.thirdjsoncalltoken,
},
})
.then((response) => response.json())
.then((responseJson) => {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(responseJson),
}, function() {
// do something with new state
});
})
.catch((error) => {
console.error(error);
});
}
navigate(routeName) {
this.props.navigator.push({ name : routeName });
}
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
const menu = <Menu onItemSelected={this.onMenuItemSelected} />;
return (
<SideMenu
menu={menu}
isOpen={this.state.isOpen}
onChange={(isOpen) => this.updateMenuState(isOpen)}>
<View style={styles.container}>
<Text>TicketID tt : {this.state.tikid} </Text>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) =>
<View style={{marginTop: 10}} >
<Text style={{marginTop: 3}} >Ticket History</Text>
<Image style={{height: 50, width: 50} } source={ require('../assests/companyIcon.png') } />
<Text style={{marginTop: 3}} >MailSubject : {rowData.MailSubject}</Text>
<Text style={{marginTop: 3}} >TicketID : {rowData.TicketID}</Text>
<Text style={{marginTop: 3}} >SendTo : {rowData.SendTo}</Text>
<Text style={{marginTop: 3}} >Body : {rowData.Body}</Text>
<Text style={{marginTop: 3}} >CompanyID : {rowData.CompanyID}</Text>
<Text style={{marginTop: 3}} >QueueDate : {rowData.QueueDate}</Text>
<Text style={{marginTop: 3}} >AttacmentIDsString : {rowData.AttacmentIDsString}</Text>
<Text style={{marginTop: 3}} >AttacmentNamesString : {rowData.AttacmentNamesString}</Text>
<Text style={{marginTop: 3}} >AgentProfileToken : {rowData.AgentProfileToken}</Text>
<Text style={{marginTop: 3}} >CreatedUserEmail : {rowData.CreatedUserEmail}</Text>
<Text style={{marginTop: 3}} >BadgeType : {rowData.BadgeType}</Text>
<Text style={{marginTop: 3}} >CreatedUserName : {rowData.CreatedUserName}</Text>
</View>
}
/>
</View>
<Button style={styles.button} onPress={() => this.toggle()}>
<Image
source={require('./menu.png')} style={{width: 32, height: 32}} />
</Button>
</SideMenu>
);
}
}
const styles = StyleSheet.create({
container: {
flex : 1,
flexDirection : 'column',
//justifyContent: 'center',
//alignItems: 'center',
backgroundColor : '#F3F3F4',
}
,navMenuBtn : {
}
,navMenuIcon : {
height : 50,
width : 30,
marginLeft : 15
}
});
class Button extends Component {
handlePress(e) {
if (this.props.onPress) {
this.props.onPress(e);
}
}
render() {
return (
<TouchableOpacity
onPress={this.handlePress.bind(this)}
style={this.props.style}>
<Text>{this.props.children}</Text>
</TouchableOpacity>
);
}
}
AppRegistry.registerComponent('ticketApp12', () => ticketApp12);
有人可以帮我解决这个问题。