0

this page is a view in a RoR project and i need to build this array of arrays using jQuery and JavaScript :

{ {id, mode, val_a, val_b}, {id, mode, val_a, val_b}, {id, mode, val_a, val_b} }

i think my build process is good

var arraytutti = [];
$('.selettoremodo').each(function() {
  arraysingolo = [];
  work = this.id;
  modo = this.value;
  orecontabilizzate = $("." + work + "[name='durataore_contab']").val();
  minuticontabilizzati = $("." + work + "[name='durataminuti_contab']").val();
  arraysingolo.push(work, modo, orecontabilizzate, minuticontabilizzati)

  arraytutti.push(arraysingolo)
});

printing in console log the main array with "console.log(arraytutti)" i have this (see picture)

chrome js console

Now i need to pass ALL THIS ARRAY WITH STRUCTURE to a field, but using $("#appoggio").html(arraytutti.toString());

or

$("#appoggio").html(arraytutti);

i have something like

389,2,3,0,391,2,4,0,393,2,0,24,395,2,8,41

i need the full array's structure so i can pass the field by post and analize the data from the controller,

how can i solve?

2
  • did you try JSON.stringify(arraytutti)???? Commented Sep 26, 2016 at 19:38
  • Thank you @pavlos !! this solved my problem!! Commented Sep 26, 2016 at 19:41

3 Answers 3

1

You simply need to call JSON.stringify(arraytutti), and decode the JSON on the server side.

Sign up to request clarification or add additional context in comments.

Comments

0
$("#appoggio").html(JSON.stringify(arraytutti)); 

Comments

0

you can do something like this in ruby controller on this params:

#=> [389, 2, 3, 0, 391, 2, 4, 0, 393, 2, 0, 24, 395, 2, 8, 41]

params[:something].each_slice(4).map{|l| l}
#=> [[389, 2, 3, 0], [391, 2, 4, 0], [393, 2, 0, 24], [395, 2, 8, 41]]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.