johntanquinco
johntanquinco

Reputation: 1393

Access field in graphQL array query dynamically

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)

Upvotes: 1

Views: 658

Answers (1)

Asha
Asha

Reputation: 760

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.

Upvotes: 1

Related Questions