1

I have the following return code

return (
  <FlatList
    data={data.groupQuery.entities}
    keyExtractor={(item, index) => index}
    renderItem={
      ({ item }) => {
        return (
          <View style={styles.container}>
            />
            <Text style={styles.label}>Name: {item.fieldName}</Text> // I want to display fieldName value here
          </View>
        )
      }
    }
  />
);

Given the above, how can I access the fieldName values from the query array in the photo. I want to call the field dynamically.


Updated query:

Apologies for some confusion to this thread. Now my goal is to access the fieldName value from the photo below. I tried {item.fieldTradingPlatform.entity.fieldName} but getting TypeError: Cannot read property 'fieldName' of undefined

enter image description here


Previous query:

enter image description here

With static call, I can output the value of first array:

console.log(data.groupQuery.entities[0].fieldName)
6
  • Is the above code not working? What behavior are you seeing? What behavior did you expect? Are you seeing any errors in the console? Commented Nov 2, 2018 at 4:15
  • I actually have 2 different queries... 1> without the integer array, and {item.fieldName} outputs the fieldName. 2> This updated version of my query. So I want to know how to dynamically call the values. Commented Nov 2, 2018 at 4:32
  • My concern is im not sure how to restructure the code so I can get both the [0] and [1] values from that query. Should we define an index value? Then how I can add this? Commented Nov 2, 2018 at 4:35
  • 1
    The FlatList component already dynamically creates a view for each item in the array of items you pass to the data prop. The value of each item is available inside the renderItem function. You're already dynamically rendering some views based on the passed-in array. If you have two items in your array, a separate view should be rendered for each of those items. Commented Nov 2, 2018 at 4:46
  • 1
    Again, it's not clear from your question and your comments what behavior you're expecting and what you're actually seeing when you run your code. What about your current code is not working as expected? Commented Nov 2, 2018 at 4:48

1 Answer 1

1

Graph Query Data

Try like this to access field name

renderItem={({ item }) => (
                    <View>
                        {
                            item.fieldTradingPlatform.map((a, i) => {
                                return <Text>{a.entity.fieldName}</Text>
                            })
                        }
                    </View>)}

fieldTradingPlatform is a array not a single object.

Sign up to request clarification or add additional context in comments.

2 Comments

You are genius. Thank you so much!
BTW, I get this warning in the app and console UI Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of CellRenderer. See https://fb.**/react-warning-keys for more information. in View (at PlatformComponent.js:74) in line <View... of item.fieldTradingPlatform.map((a, i) => { return ( <View style={styles.container}>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.