How to split returned item in jQueryUI autocomplete?
Here's the returned data:
- var availableTags = [
- 'ActionScript|AppleScript|Asp',
- 'BASIC',
- 'Clojure|C++|C|COBOL|ColdFusion',
- 'Erlang',
- 'Fortran',
- 'Groovy',
- 'Haskell',
- 'Java|JavaScript',
- 'Lisp',
- 'Perl|PHP|Python',
- 'Ruby',
- 'Scala|Scheme',
- ];
How can I split the items into arrays during the `renderItem` function,and when users type PHP it will only return PHP from 'Perl|PHP|Python'?
Here's my code:
- $('#tags').autocomplete({
- source: availableTags,
- search: function(event, ui) {
- $('#wrapper').empty();
- },
- })
- .data('autocomplete')._renderItem = function(ul, item) {
- return $('<div class="element"></div>')
- .data('item.autocomplete', item)
- var smallchoice = item.label.split('|');
- $.each(smallchoice,function(j,smallchoice){
- $option = '<a href="#" >' + smallchoice+ '</a>'
- })
-
- .append($option)
- .appendTo($('#wrapper'));
- };