Indexing into Data Structures

Hi everyone!

So this is a concept I am quite comfortable with in traditional programming, but am struggling with it in Wappler. I am sure it comes down to just not knowing the proper syntax so I’m calling in a lifeline!

I am inside of a repeat and need to build off of some previous values, with each iteration building off prior values (to achieve a “smoothing effect” in this particular metric). In the screenshot below, the gain_avg in object 15 is going to be based off of the gain_avg value in the previous object $14.gain_avg value.

I can successfully decrement the index using this notation {{$index-1}} but how do I get to the gain_avg property belonging to this object? {{$index-1.gain_avg}} and {{($index-1)gain_avg}} don’t work.

:sunglasses:

{{Yourdatabind.api.xxxx[$index].gain_avg}}

{{($index-1).gain_avg}}

1 Like

To fully understand App Connect and its data bindings, you must understand how App Connect elements are structured.

First all App Connect components, are exactly structured as the html flow. That is because they are html custom elements. So they can easily be nested in each other.

Every App Connect element creates its own scope. In its scope, his properties and direct children exist.

The best way to visually this is just to look at the data picker and its hierarchy:

You can access the data from every element by using its name. But it all depends where are you accessing the data. If you are on the top level. you will have to go from the top and specify all the children you want.

Like in the above example if I want to get the api start_at, I will have to type api1.data.start_at

But if I’m already in a repeater - they I’m in its scope, so can specify the children directly.

image

But from outside I will have to like:

image

So you really have to go with the objects hiarchy.

Onze you get that it will all make sense :slight_smile: and the Data Bindings picker does the most work for you so you don’t have to know it - just pick :slight_smile:

1 Like