Page 1 of 1

Passing a column of values from my database into an array

Posted: Tue Aug 05, 2014 5:09 pm
by Jared7025929

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


Passing a column of values from my database into an array

Posted: Tue Aug 05, 2014 5:32 pm
by Evgene Karachevtsev

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


Passing a column of values from my database into an array

Posted: Tue Aug 05, 2014 5:39 pm
by Jared7025929

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?


Passing a column of values from my database into an array

Posted: Tue Aug 05, 2014 8:01 pm
by Evgene Karachevtsev

Jared,

Yes, it is correct.


Passing a column of values from my database into an array

Posted: Wed Aug 06, 2014 5:34 pm
by Jared7025929

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.


Passing a column of values from my database into an array

Posted: Wed Aug 06, 2014 7:27 pm
by Jared7025929

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

Thank you!


Passing a column of values from my database into an array

Posted: Wed Aug 06, 2014 7:53 pm
by Evgene Karachevtsev

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


Passing a column of values from my database into an array

Posted: Wed Aug 06, 2014 7:56 pm
by Jared7025929

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.


Passing a column of values from my database into an array

Posted: Thu Aug 07, 2014 3:18 am
by Yurii Orishchuk

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.