0

I would like to set the source of autocomplete to the one that can have value/label pairs as described in their documentation here

http://api.jqueryui.com/autocomplete/

They say that

An array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]

The label property is displayed in the suggestion menu. The value will be inserted into the input element when a user selects an item. If just one property is specified, it will be used for both, e.g., if you provide only value properties, the value will also be used as the label.

In my code I have

html

 <input type="text" id="testBox" name="testBox" maxlength="70"/>

in my js

var catsArr = [];
                for (var i = 0; i < 10; i++) {
                    var cat = {
                        label: "grey " + i,
                        value: i
                    };
                    catsArr.push(cat);
                }

                //tie the autocomplete to the box
                $("#testBox").autocomplete({ source: catsArr });

But somehow, when the user starts typing the word grey, nothing shows up....What am I missing?

4

0 回答 0