0

Using JQuery UI widget to try and call in this js file of string data but getting 'no results found'. No console errors. I simply don't think I'm referencing this correctly as I'm not very proficient with jquery/js. If someone could point me in a direction, I'd appreciate it.

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

scripts

<script src='js/jquery-1.11.0.min.js'></script>
<script src="js/autocomplete/jquery-ui-1.10.3.custom.js" type="text/javascript" charset="utf-8"></script>
<script src="js/Providers.js" type="text/javascript" charset="utf-8"></script>

formatted in file

var providerdata=[{"ProviderID":"1","NAME":"name1"},{"ProviderID":"2","NAME":"name2"},{"ProviderID":"3","NAME":"name3"}];

calling

$('#test').autocomplete({
    source: providerdata,
    success: function(data) {
            var cat_data = $.map(data.Providers, function(item) {
                return {
                    value: item.NAME,
                    label: item.NAME,
                };
            });
            $("#test").autocomplete({
                minlength:3,
                delay: 500,
                source: cat_data               
            });
        }
});
user3191137
  • 135
  • 3
  • 11

1 Answers1

1

uhm... i'm not sure, but i don't think that autocomplete has success property because its a property of an ajax call... maybe you use it inside an ajax call to get back the source, but in your case you already has surce providerdata, true?

Assuming that your $.map works fine, you can do something like:

var cat_data = $.map(providerdata, function(item) {
      return {
        value: item.NAME,
        label: item.NAME,
      }
});

$('#test').autocomplete({
    source: cat_data,
    minlength:3,
    delay: 500,
});

[edit] - i see doc and i think you can do also:

$('#test').autocomplete({
    source: function(){
        return $.map(providerdata, function(item) {
            return {
                 value: item.NAME,
                 label: item.NAME,
            };
        })
    },
    minlength:3,
    delay: 500,
});

is it works?

Frogmouth
  • 1,808
  • 1
  • 14
  • 22
  • Thanks, that's all I needed. I figured it was too much as I got it to work from a json file calling with ajax but was gettting this error.http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-access-allow-for-file But I hardly code with js/jquery so I dont know this stuff. thanks! – user3191137 Jan 14 '14 at 16:13
  • my english is bad and i don't understand all your comment. But if you solved your problem and i helped you... let's rock mate! – Frogmouth Jan 14 '14 at 16:16