commadelimited/autoComplete.js

Controlling data from source

Closed this issue · 3 comments

It s happens that you are looking for label and value in a complex data json structure. our api returns value in the format
[
{id: 123, name: "ABC"},
{id: 133, name: "XYZ"}
]

obviously this does not work.
It would be great if you could let us control, how to transform this data to the format you require. It would help instead of changing code in the API (may be some who does noth ave access to the API code, might feel good)

Hi,
i think your can use the dataHandler for this kind of stuff:
dataHandler : fn(), // optional function to convert the received JSON data to the format described below

If u use underscore js you can use something like:

dataHandler: function(json) {
    return _.map(json, function(yourObject) {
        return {
            value: yourObject.id,
            label: yourObject.name
        };
    });
}

Hope this helps,
Tom

Thanks Tom, that helps

Thanks Tom