Autocomplete using JSON value in variable for source?


  1. [ "Choice1", "Choice2" ]
  2.        
  3. [ { label: "Choice1", value: "value1" }, ... ]
  4.        
  5. $('input').autocomplete({source: [ "Choice1", "Choice2" ], minLength: 0});
  6.        
  7. $('input').autocomplete({source: [ { label: "Choice1", value: "value1" } ], minLength: 0});
  8.        
  9. var source = '[ "Choice1", "Choice2" ]';
  10. $('input').autocomplete({source: source, minLength: 0});
  11.        
  12. $('input').autocomplete({source: $('input').data('json'), minLength: 0});
  13.        
  14. $('input').autocomplete({source: eval($('input').attr('data-json')), minLength: 0});
  15.        
  16. var source = '[ "Choice1", "Choice2" ]';
  17.        
  18. var source = [ "Choice1", "Choice2" ];
  19.        
  20. var source = JSON.parse( '[ "Choice1", "Choice2" ]' );
  21.        
  22. var source = $.parseJSON( '[ "Choice1", "Choice2" ]' );
  23.        
  24. [ { label: "Choice1", value: "value1" }, ... ]
  25.        
  26. [ { "label": "Choice1", "value": "value1" }, { "label": "Choice2", "value": "value2" },...]


Learn More :