Database to array

What is the best way to add records from a serviceconnect into an array on the client side?

I would have expected this to work:
<dmx-array id="arr1" dmx-bind:items="serverconnect.data.query1.where('Column_A', 'Record_A', '==')"></dmx-array>

If you use the UI to do this it generates the following code which is correct:

 <dmx-array id="arr1" dmx-bind:items="serverconnect1.data.query.data.where(`column_name`, 'some value', '==')"></dmx-array>

Thanks for your swift reply.

I’ve copy/pasted your code (renamed column_name and some value), but nothing gets loaded into the array when I use {{arr1.items}}

what do you mean? Are you sure your server action returns records?
you can see your array component in the browser console as well using dmx.app.data

It actually loads the records as objects.

array = [object Object],[object Object],[object Object],[object Object]

How can I specify a specific column, ie display values?

Can you maybe explain in details what are you trying to achieve, what data do you have and what needs to be done on the page?

Of course. I am working with SVG graphics where I implement text onto the graphs. The text is stored in a DB table with the following (simplified) structure:

ModuleID, QuestionID, Answer

To load these texts directly in the SVG code, I am using a serverconnect “get_answers”. The serverconnect is a simple data retrieval of all records of the user that is logged on.

Then in the SVG code I add:

<text fill="rgb(4, 25, 70)" font-family="HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="20" x="537.58" y="887" text-anchor="middle">
   <tspan x="575" y="920">{{get_answers.data.query1.where('ModuleID', 'values', '==')[1].Answer}}</tspan>
</text>

to display the text.

This works fine, but the code might be more elegant and scalable if I load these texts into an array beforehand so I can standardize the SVG code by referring to the array.

Hope this makes sense.

So what exactly do you want to store in the array? What structure/what data?

I want to store in the array: all the values from column “Answer” where column “ModuleID” == ‘values’. Just as a simple array

Then you need to do:

 <dmx-array id="arr1" dmx-bind:items="serverconnect1.data.query.data.where(`column_name`, 'some value', '==').values(`column_name_to_be_stored`)"></dmx-array>
1 Like

So .values() is how one can enter the nest! Thanks, that works.

1 Like