Consider the scenario where I attempt to generate something similar to the following:
@data = Array.new
for i in 0..1
j = 2
@data << ["Id" => i, "Label" => j]
end
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @nodes }
This will produce the following JSON data:
[[{"Id":0,"Label":2}], [{"Id":1,"Label":2}]]
Subsequently, when accessing this data in Java Script, the syntax array[i][0].id
is needed to retrieve the id. Ideally, it should simply be array[i].id
for easier access.
Any recommendations or suggestions?