Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. //html
  2. <div id="the-basics">
  3. <input class="typeahead form-control" type="text" placeholder="Search Users" >
  4. </div>
  5. //ts
  6. export class Asd{
  7. substrRegex;
  8. temp;
  9. suggestMatch;
  10.  
  11. search;
  12.  
  13. attached(){
  14. this.searchFun();
  15. }
  16.  
  17. async searchFun(){
  18. var substringMatcher = function(strs) {
  19. return async function findMatches(q, cb) {
  20. var matches, substrRegex;
  21.  
  22. // an array that will be populated with substring matches
  23. matches = [];
  24.  
  25. // regex used to determine if a string contains the substring `q`
  26. substrRegex = new RegExp(q, 'i');
  27.  
  28. // iterate through the pool of strings and for any string that
  29. // contains the substring `q`, add it to the `matches` array
  30. $.each(strs, function(i, str) {
  31. if (substrRegex.test(str)) {
  32. matches.push(str);
  33. }
  34. });
  35.  
  36. cb(matches);
  37. console.log(matches)
  38. this.suggestMatch = await matches;
  39. console.log('suggested'+this.suggestMatch)
  40. };
  41. };
  42.  
  43. var states =
  44. [
  45. {
  46. "firstName": "Trajko",
  47. "lastName": "Trajkov",
  48.  
  49. "image":"http://placehold.it/50x50",
  50.  
  51. },
  52.  
  53. {
  54. "firstName": "Petko",
  55. "lastName": "Petkov",
  56.  
  57. "image":"http://placehold.it/50x50",
  58. },
  59. {
  60. "firstName": "Stanko",
  61. "lastName": "Stankov",
  62.  
  63. "image":"http://placehold.it/50x50",
  64.  
  65. }
  66. ]
  67.  
  68. this.temp = $('#the-basics .typeahead')
  69. this.temp.typeahead({
  70. hint: true,
  71. highlight: true,
  72. minLength: 1,
  73.  
  74. },
  75. {
  76. name: 'states',
  77. source: substringMatcher(states),
  78. templates: {
  79. empty: [
  80. '<div class="empty-message">',
  81. 'Unable to find result',
  82. '</div>'
  83. ]
  84. .
  85. join('<br>'),
  86. suggestion: function(data){
  87. return '<p><img src=' + data.image + '/>' +' '+ data.firstName +' '+data.lastName+'</p>';
  88. },
  89. footer: '<hr><a href=#> See All </a>'
  90.  
  91. },
  92.  
  93.  
  94. });
  95.  
  96.  
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement