Created
October 11, 2012 07:14
-
-
Save pixtur/3870727 to your computer and use it in GitHub Desktop.
ninja-autocomplete 1.01 example with rich data storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ac= new $.Ninja.Autocomplete($(".myinput"), { | |
get:function (q, callback) { | |
$.ajax({ | |
url: 'http://completion.amazon.com/search/complete', | |
dataType: 'jsonp', | |
data: { | |
q: q, | |
mkt: 1, | |
'search-alias': 'dvd' | |
}, | |
success: function (data) { | |
var rich_value_map = {}; | |
values= $.map(data[1], function (item) { | |
rich_value_map[item]= item + "XYZ"; | |
return item; | |
}); | |
$('input.myinput').data('rich-values', rich_value_map); | |
callback(values); | |
}, | |
error: function (request, status, message) { | |
$.ninja.error(message); | |
} | |
}); | |
}, | |
select:function() { | |
var rich_value = $('input.myinput').data('rich-values')[ this.$element.val() ]; | |
console.log('rich-value:' + rich_value); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment