In perl hashes are unordered. But if they were, you case wouldn't be working too(because in js objects are unordered too, unlike ES6 "Set").

But you can use the result in your case as array without modification:

#server
$data = [1,2,3];
return $self->render(json => { data => $data }); # NOT (json => $data)!

// browser
res.json.data.forEach(el => console.log(el));



Hello guys, I'm new to the group and to Mojolicious,
I was curious to try it out earlier on and I noticed that when retrieving data from the db and parsing it to json, the data can assume different patterns and the elements are not always displayed in the browser with the same sequence... The key->value relationship is always correct, just the order of data, data1,data2 changes. Is that normal?
How can that be solved?

The code I use is the following:
|
my$SQL ="SELECT * FROM Persons WHERE PersonID=$id";
my$cursor =$self->db->prepare($SQL);
    $cursor->execute;
my@data=$cursor->fetchrow();
    $cursor->finish();
    $self->db_disconnect();

return$self->render(json =>{data =>$data[0],data1=>$data[1],data2=>$data[2]});
|


Thank you.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to