tags:

views:

77

answers:

0

Hi,

I want to implement the jQuery autocomplete using json. This is my setup:

JS code:

$("#searchstring").autocomplete("/cities/<countrycode>/<citycode>/json", {
    parse: prep_data,
    formatItem: format_item
});         
prep_data = function(data){
    tmp = $.evalJSON(data);
    parsed_data = [];
    for (i=0; i < tmp.length; i++) {
        obj = tmp[i];             
        parsed_data[i] = { 
            data: obj ,
            value: obj.cityname,
            result: obj.id
        };
    }
    return parsed_data;
}         
format_item = function (item, position, length){
    return item;
}

this is what my json object returns:

[{"cityname":"chennai","id":"146"},{"cityname":"chepzi","id":"140"}]

How to list cityname values alone in the textbox.. (i.e) how to retrieve these values in the correct format.