0

I have few lines of code, but is not working, I can't understand why. Please, if someone tell me where i am wrong

var data = {
    "sugestii":[{
        "nume":"Hunedoara (tot judeţul)",
        "id":"123220",
        "tip":2
    },{
        "nume":"Hunedoara (din judeţul Hunedoara)",
        "id":"126958",
        "tip":1
    },{
        "nume":"Hunia (din judeţul Dolj)",
        "id":"101566",
        "tip":1
    },{
        "nume":"Hunedoara Timisana (din judeţul Arad)",
        "id":"14257",
        "tip":1
    }]
}
  // setup autocomplete function pulling from data [] array
  $('#autocomplete').autocomplete({
    lookup: data,
    onSelect: function (suggestion) {
      var thehtml = '<strong>data  Name:</strong> ' + suggestion.nume + ' <br> <strong>Symbol:</strong> ' + suggestion.id;
      $('#outputcontent').html(thehtml);
    }
  });
Kiran Shinde
  • 5,732
  • 4
  • 24
  • 41
Silviu
  • 175
  • 5
  • 15

2 Answers2

0

Believe, there is no option as lookup in autocomplete, try replacing lookup with source. Read here http://api.jqueryui.com/autocomplete/

Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
  • That is true, i think it was available in older versions. The following example: http://designshack.net/tutorialexamples/html5-autocomplete-suggestions/ Is using `V1.9.1`. If you look at the source it uses `lookup` and works. However the docs for `v1.9` say `source` not `lookup`. The OP's fiddle is using `v1.10.3` i believe. So probably been looking at old examples. – ste2425 Sep 24 '15 at 08:38
  • [designshack.net/tutorialexamples/html5-autocomplete-suggestions](http://designshack.net/tutorialexamples/html5-autocomplete-suggestions/) this link uses lookup with an array attribute. However OP's trying to pass data which is an array. Probably lookup takes array and not an object. – Saurabh Tiwari Sep 24 '15 at 09:32
0

You can use in success method of autocomplete like this, hope so its help you out...

success: function (data) {
    response($.map(data, function (item) {
           return {
                     label: item.name,
                     value: item.id
                  };
    }));
}