如何为Jquery的自动完成格式化JSon

时间:2011-07-01 15:12:04

标签: jquery ruby-on-rails jquery-ui autocomplete

我正在使用RoR和Jquery编写自动填充字段。

当我致电getJson时:

var aeropuertos;
    $.getJSON('web_services/get_airports', function(data) {
        aeropuertos = data;
    });

    $("#airports_input_origen").autocomplete({source:aeropuertos});
    $("#airports_input_destino").autocomplete({source:aeropuertos});

我明白了:

[
    [
        "(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"
    ]
]

但似乎格式不正确,因为自动完成功能不起作用并且抛出此错误:

  

this.source不是函数

-----------------已解决--------------

这是一个JSON格式问题!

而不是发送[[“”,“”,...],...]

我必须发送:[“.......”,“.........”,....]

(解决方案:Create JSON of one dimension Ruby

无论如何,谢谢你的时间! =)

0 个答案:

没有答案