Jared7025929
Posts: 0
Joined: Tue Aug 05, 2014 5:09 pm

Passing a column of values from my database into an array

I specifically need to understand how to pass a single column of information from my database into an array. Then I will use a javascript for loop to total the contents of the array.

I have read over every API documentation and tutorial I can find on your site and I'm just not understanding it. I may need it broken down even further if your tutorials already teach this simple process.

Thank you

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Passing a column of values from my database into an array

Hello Jared,

The whole response of the service is available on the event Success, in the variable data. If your service returns an array of objects, then this variable will be the array that you are looking for

Jared7025929
Posts: 0
Joined: Tue Aug 05, 2014 5:09 pm

Passing a column of values from my database into an array

So is this what I do?

  1. Create a "list service" that grabs the data from the column I want

  2. Then within the "on success" event, implement my javascript "for loop" to total all the values now contained within the "data" variable

    In that correct?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Passing a column of values from my database into an array

Jared,

Yes, it is correct.

Jared7025929
Posts: 0
Joined: Tue Aug 05, 2014 5:09 pm

Passing a column of values from my database into an array

Ok, I created a simple success event to check to see if I could access the "data" variable and to no avail. I even attempted accessing the variable as an array ie: data[1], data[0][0].

Here is what I've got so far. What am I doing wrong?

  1. Pic of my database. I am attempting to add all the values stored in the cubicY column:
    Image

  2. My database services. I am trying to use the "addItems" one for this procedure.
    Image

  3. The mapping for the addItems event service.
    Image

  4. The on success event code to see what I've got stored in the data variable
    Image

  5. The resulting alert box when the app in run.
    Image

    Thanks for your time.

Jared7025929
Posts: 0
Joined: Tue Aug 05, 2014 5:09 pm

Passing a column of values from my database into an array

Still unsure how to implement what you told me. Please see my post below.

Thank you!

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Passing a column of values from my database into an array

Jared,

data - an array of objects containing the filds description, cubicY, etc. To read all the values of cubicY, you should go through this array like this:
predata.each(function(){
alert(this.cubicY);
});/pre

Jared7025929
Posts: 0
Joined: Tue Aug 05, 2014 5:09 pm

Passing a column of values from my database into an array

Thank you Evgene. Can you direct me to any tutorials that cover this "data.each"? I want to know and understand the different commands I can use with the data variable.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Passing a column of values from my database into an array

Hi Jared,

Please take a look here about ".each" jQuery functionality. http://api.jquery.com/each/

Also given code should be:

pre

jQuery(data).each(function(){
alert(this.cubicY);
});

/pre

Regards.

Return to “Issues”