Guest User

Untitled

a guest
Dec 7th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. ...
  2. {OriginDestinationLocations:{DestinationLocation:{CityName:'Orlando'}, OriginLocation:{CityName:'Miami'}}},
  3. {OriginDestinationLocations:{DestinationLocation:{CityName:'Orlando'}, OriginLocation:{CityName:'Chicago'}}},
  4. {OriginDestinationLocations:{DestinationLocation:{CityName:'Las Vegas'}, OriginLocation:{CityName:'Miami'}}}
  5. ....
  6. // so here (pretending that would be the full list) when I pick Orlando as origin in the 1st selection field, I should only see Miami and Chicago in the second field.
  7.  
  8. class App extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. from:[],
  13. to:[]
  14. }
  15. }
  16. componentDidMount() {
  17. cityPairs().then(response => {
  18. let from = [];
  19. let to = [];
  20. // here its wrong to separate destination and origin as origin needs to stay 'connected' to the matching destinations but I just don't know what else to do. if I push objects with always matching origins/destinations into 1 array, I was thinking it would create so many pair, that can't be right in terms of performance etc. or would that be the only way?
  21. for (var i = 0; i < response.length; i++) {
  22. from.push(response[i].DestinationLocation.CityName);
  23. to.push(response[i].OriginLocation.CityName);
  24. }
  25. this.setState({
  26. to: to,
  27. from: from
  28. })
  29. })
  30. }
  31.  
  32. handleChange(event) {
  33. this.setState({value: event.target.value});
  34. }
  35. render(){
  36. return (
  37. <div>
  38. <Select
  39. name="form-field-name"
  40. value={this.state.value}
  41. onChange={this.handleChange}
  42. clearable={this.state.clearable}
  43. searchable={this.state.searchable}
  44. labelKey='name'
  45. valueKey='cityCode'
  46. options={this.state.to}
  47. />
  48. </div>
  49. )
  50. }
  51. }
Add Comment
Please, Sign In to add comment