I'm writting an Autocomplete field using RoR and Jquery.
When I call getJson
:
var aeropuertos;
$.getJSON('web_services/get_airports', function(data) {
aeropuertos = data;
});
$("#airports_input_origen").autocomplete({source:aeropuertos});
$("#airports_input_destino").autocomplete({source:aeropuertos}开发者_如何转开发);
I get this:
[
[
"(GKA)",
"GOROKA",
"GOROKA",
"PAPUA NEW GUINEA"
],
[
"(LAE)",
"LAE",
"PAPUA NEW GUINEA",
"00"
],
[
"(MAG)",
"MADANG",
"MADANG",
"PAPUA NEW GUINEA"
],
[
"(HGU)",
"MOUNT HAGEN",
"MOUNT HAGEN",
"PAPUA NEW GUINEA"
],
[
"(LAE)",
"NADZAB",
"NADZAB",
"PAPUA NEW GUINEA"
]
]
But it seems that the format isn't right since the autocomplete is not working and is throwing this error:
this.source is not a function
----------------- SOLVED --------------
It was a JSON format Issue!
Instead of sending [ ["", "" , ...] , ... ]
I had to send: [ "......." , ".........", ....]
(solution: Create JSON of one dimension Ruby)
Thx anyway for your time! =)
精彩评论