JQuery autocomplete issue

I'm using the JQuerys Autocomplete plugin, but it doesn't autocomplete when I type anything.

Any ideas why this isn't working? Basic example works, but not mine.

var ppl = {"ppl":[{"name":"peterpeter", "work":"student"},
     {"name":"piotr","work":"student"}]};

var options = {
    matchContains: true,  // So we can search inside string too
    minChars: 2,      // this sets autocomplete to begin from X characters
    dataType: 'json', 
    parse: function(data) {
        var parsed = [];
        data = data.ppl;
        for (var i = 0; i < data.length; i++) {
            parsed[parsed.length] = {
                data: data[i],  // the entire JSON entry
                value: data[i].name,  // the default display value
                result: data[i].name // to populate the input element 
            };
        }
        return parsed;
    },
    // To format the data returned by the autocompleter for display
    formatItem: function(item) { 
        return item.name; 
    }
};

$('#inputplace').autocomplete(ppl, options);

      

Ok. Updated:

<input type="text" id="inputplace" />

      

So, when you enter, for example, "peter" in the input field. Autocomplete suggestions are not displayed. It should give "peterpeter", but nothing happens.

One more thing. Using this example works great.

var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" ");
$("#inputplace").autocomplete(data);

      

+2


a source to share


1 answer


Well, looking at the code in this plugin, the "parse" parameter looks like it's only being called when the data is being retrieved by the AJAX call. As an experiment, you can try to pass data in such a way that you don't need it:



var ppl = [{"name":"peterpeter", "work":"student"},
 {"name":"piotr","work":"student"}];

      

+3


a source







All Articles