开发者

JQuery autocomplete problem

Im using JQuerys Autocomplete plugin, but it doesn't autocomplete upon entering anything.

Any ideas why it doesnt work? The 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开发者_Python百科 // 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 entering for example "peter" in the input field. No autocomplete suggestions appear. It should give "peterpeter" but nothing happens.

And one more thing. Using this example works perfectly.

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


Well, looking at the code in that plugin, the "parse" option looks like it's only called when the data is retrieved by an AJAX call. As an experiment, you might try passing in the data such that you don't need it:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜