开发者

How to format JSon for Jquery's Autocomplete

开发者 https://www.devze.com 2023-03-16 14:44 出处:网络
I\'m writting an Autocomplete field using RoR and Jquery. When I call getJson: var aeropuertos; $.getJSON(\'web_services/get_airports\', function(data) {

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! =)

0

精彩评论

暂无评论...
验证码 换一张
取 消