i'm struggling implementing jquery plugin site tags (with custom data objects) autocomplete. jquery textext can found here (http://textextjs.com/). i'm struggling using custom data objects each tag, can chosen autocompletes. based on example (http://textextjs.com/manual/examples/tags-with-custom-data-objects.html) i'm trying figure out how return both "name" , "id" when tag chosen. know how achieve or point me in correct direction?
perhaps answer somewhere in example (http://textextjs.com/manual/examples/filter-with-suggestions.html)?
here's have written, isn't working (it returns name, i've tried adding 'item.id' functions didn't work me either):
<script type="text/javascript"> jquery(document).ready(function( $ ){ jquery('#textarea').textext({ plugins: 'tags', items: [ { name: 'php', id: '1' }, { name: 'closure', id: '2' }, { name: 'java', id: '3' } ], ext: { itemmanager: { stringtoitem: function(str) { return { name: str }; }, itemtostring: function(item) { return item.name ; }, compareitems: function(item1, item2) { return item1.name == item2.name; } } } }); }) </script>
your itemmanager code should this, need store suggestions in custom array relevant ids in stringtoitem method
itemmanager: { items: [], // custom array used lookup id stringtoitem: function(str) { //lookup id given str our custom array (var i=0;i<this.items.length;i++) if (this.items[i].name == str) { id = this.items[i].id; break; } return { name: str, id: id }; }, itemtostring: function(item) { //push items our custom object this.items.push(item); return item.name ; }, compareitems: function(item1, item2) { return item1.name == item2.name; } }