So I posed the question on the Domino/Notes 8.5 discussion board of how to use the jQuery autocompleter to pull data from a standard Notes view. The jQuery Autocompleter is a jQuery plugin that performs real-time autcompletion of a text-field using JSON data transferred over the wire. In this case I'm interested in the "People" view of the Notes NAB to create a dirt-simple, concise names lookup for web input. I know I can take advantage of Domino's ability to spit out JSON (or XML, for that matter) using the readviewentries&outputformat=JSON URL modifiers for a Notes view. The problem is that the standard JSON emitted by Domino conforms to its byzantine DOM (the Domino Object Model, not to be confused with the W3C standard's Document Object Model.) The data I need, namely names, must be teased out of the emitted JSON for consumption by the jQuery autocompleter. But how? Luckily, another excellent programmers' resource, the highly recommend stackoverflow.com, put me on the right track towards the answer. Apparently there is an, as yet, undocumented parse method of the autocompleter that can override the default parsing method to tease out the desired data. The last thing that needs to be done is send the "Startkey" querystring param over the wire using the extraParams parameter of the autocompleter. By default the autocompleter will send the value over the wire we want as a "q=?" querystring parameter and instead of hacking the autocomplete plugin's core .js file to change that we can just append the same value the way we want it in the querysting. Domino will just ignore any querystring values it does not use. Once that is done, you use the documented format method to return the individual item to the autocompleter when requested. Given the HTML form text field with an ID of "completeme" I write:

  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3. $("#completeme").autocomplete("names.nsf/people?readviewentries&outputformat=JSON&count=50",{parse: prepMe, formatItem: formatMe, max: 50, extraParams: {Startkey: function() { return $("#completeme").val(); }}});
  4. });//document.ready
  5. prepMe = function(data) {
  6. var tmp = eval("(" + data + ")");
  7. var count = tmp.viewentry.length;
  8. var parsedArr = [];
  9. for (i=0;i<count;i++){
  10. var obj = tmp.viewentry[i];
  11. parsedArr[i] = {
  12. data: obj.entrydata[1].text[0],
  13. value: obj.entrydata[1].text[0],
  14. result: obj.entrydata[1].text[0]
  15. }
  16. }
  17. return parsedArr;
  19. }//prepMe
  20. formatMe = function(item, position, length){
  21. var c = item
  22. var p = c;
  23. return item;
  24. }//formatMe
  25. </script>