Guest User

Untitled

a guest
Aug 10th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. const baseUrl = 'http://services.odata.org/V4/TripPinService/People';
  2. const query = { filter: { FirstName: 'Russell' } };
  3.  
  4. <OData baseUrl={baseUrl} query={query}>
  5. { ({ loading, error, data }) => (
  6. <div>
  7. { loading && {/* handle loading here */} }
  8. { error && {/* handle error here */} }
  9. { data && {/* handle data here */}}
  10. </div>
  11. )}
  12. </OData>
  13.  
  14. import React, { Component } from 'react';
  15. import {
  16. Text,
  17. View,
  18. ScrollView
  19. } from 'react-native';
  20. import { List, ListItem } from 'react-native-elements';
  21.  
  22. import OData from 'react-odata';
  23. const baseUrl = 'http://PRIVATE/odata/Products';
  24. // according to the code in odata.js we use false to send no options
  25. // I also tried using { filter: { ProductId: 1 } };
  26. // I also tried using { filter: { ProductId: '1' } };
  27. const query = false;
  28.  
  29. class ProductList extends Component {
  30. onLearnMore = (user) => {
  31. this.props.navigation.navigate('Details', { ...user });
  32. };
  33.  
  34. render() {
  35. return (
  36. <ScrollView>
  37. <OData baseUrl={baseUrl} query={query}>
  38. {({ loading, error, data }) => (
  39. <View style={{ height: 400 }}>
  40. <Text>HI THERE!!</Text>
  41. {loading && <Text>Loading...</Text>}
  42. {error && <Text>error...</Text>}
  43. {data &&
  44. <List>
  45. <ListItem
  46. key="1234"
  47. title="Sample Item" />
  48. <ListItem
  49. key="1235"
  50. title="Smaple Item 2" />
  51. {data.map((product) => (
  52. <ListItem
  53. key={product.ProductId}
  54. title={`${product.ItemCode}`}
  55. />
  56. ))}
  57. </List>
  58. }
  59. </View>
  60. )}
  61. </OData>
  62. </ScrollView>
  63. );
  64. }
  65. }
  66.  
  67. export default Feed;
  68.  
  69. componentWillMount() {
  70. alert('fetching');
  71. fetch(baseUrl)
  72. .then((response) => response.json())
  73. .then((responseJson) => {
  74. alert('returned ' + responseJson.value[0].ItemCode);
  75. return responseJson.value
  76. })
  77. .catch((error) => { console.error(error) });
  78. }
Add Comment
Please, Sign In to add comment