How can i transform this instance variable into JavaScript array of objects
I know there is something that i have to do with
but when i try it. it just completely errors out..
This is what i am getting: (comes out with the Quotes)
@updates = [
"{'24548_0_load_results': ['1630609','2015-04-07 13:51:03 UTC','7 minutes']}",
"{'24548_0_load_results': ['1630610','2015-04-07 13:51:03 UTC','7 minutes']}"
]
Created the above with this:
@updates = []
records.each do |r|
updates << "{ '" + t.search_table_id.to_s + "': " + Search.load_post_result(r, s).to_s + " }"
end
This is how i need it:
var obj1 = {
"loads": [
{'24547_1428357240_load_results' : ['1630607','2015-04-06 18:35:46 UTC','8 minutes']},
{'24547_1428357240_load_results' : ['1630606','2015-04-06 18:35:47 UTC','8 minutes']}
]
};
This is the script that i am tring to run this array of objects thru:
$.each(obj1["loads"], function(k, v){
$.each(v, function(key, value) {
alert(key + ": " + value);
})
});
edit: This is what i have now
var obj1 = {
"loads": []
};
for (string in <%= @updates1 %>){
obj1["loads"].push(JSON.parse(string.replace(/'/g,'\"')));
}
$.each(obj1["loads"], function(k, v){
$.each(v, function(key, value) {
alert(key + ": " + value);
})
});
And looks like this in the response:
var obj1 = {
"loads": []
};
for (string in ["{ '24549_1428420484_load_results': ['1630610','2015-04-07 14:44:37 UTC','44 minutes','Springfield, MO','Dallas, TX','04/07','04/07','Full','Flatbed or Van or Reefer','','53','0.00'] }", "{ '24549_1428420484_load_results': ['1630609','2015-04-07 13:51:03 UTC','about 2 hours','Springfield, MO','Dallas, TX','04/10','04/11','Full','Flatbed or Van or Reefer','','53','0.00'] }"]){
obj1["loads"].push(JSON.parse(string.replace(/'/g,'\"')));
}
$.each(obj1["loads"], function(k, v){
$.each(v, function(key, value) {
alert(key + ": " + value);
})
})
;