Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript][AJAX]Połączenie dwóch skryptów
Forum PHP.pl > Forum > Przedszkole
eminiasty
Mam kod który używa matcher, ogranicza użytkonikowi wyniki po wpisywani kolejnej litery. Coś jak tu:
http://jsfiddle.net/jwogamhw/26/
  1. function matchStart (term, text,element) {
  2. return (element.search.toUpperCase().indexOf(term.toUpperCase()) !== -1);
  3. }
  4. $("#hdn").select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
  5.  
  6. $("#hdn").select2(
  7. {
  8. width: '300px',
  9. matcher: oldMatcher(matchStart),
  10. multiple: true,
  11. data:
  12. [
  13. {
  14. id: 1,
  15. text: 'Italy',
  16. search: "bella Italia",
  17. children:
  18. [
  19. {
  20. id: 2,
  21. text: 'Sardinia',
  22. search: "bella Italia Sardinia"
  23. },
  24. {
  25. id: 3,
  26. text: 'Sicily',
  27. search: "bella Italia Sicily"
  28. }
  29. ]
  30. },
  31. {
  32. id: 4,
  33. text: 'United Kingdom',
  34. search: "United Kingdom",
  35. children:
  36. [
  37. {
  38. id: 5,
  39. text: 'Guernsey',
  40. search: "United Kingdom - Guernsey"
  41. },
  42. { id: 6, text: 'Jersey',
  43. search: "United Kingdom - Jersey"
  44. }
  45. ]
  46. }
  47. ]
  48. })
  49. .on("select2:select", function (e) { console.log("select2:select", e); });
  50.  
  51. });


Chciałbym go połączyć z tym skryptem, próbuje w ten sposob ale za nic nie chce dzialac.
Jest ktoś w stanie mi pomoc/doardzić w jaki sposob powinienem to zrobic?

  1.  
  2. $( '#hdn' ).select2({
  3. width: '100%',
  4. matcher: function matchStart (term, text,element) {
  5. return (element.search.toUpperCase().indexOf(term.toUpperCase()) !== -1);
  6. },
  7. ajax: {
  8.  
  9. url: "../inc/ajax/plik.php",
  10. dataType: 'json',
  11. delay: 250,
  12. data: function (params) {
  13. return {
  14. query: params.term // search term
  15. };
  16.  
  17. },
  18. processResults: function (data) {
  19. return {
  20. results: data
  21. };
  22. },
  23. cache: true
  24. },
  25. minimumInputLength: 1,
  26. });
bostaf
Wydaje mi się że upgrejdujesz Select2 tak? Próbowałeś tak jak to opisali http://select2.github.io/announcements-4.0...changed-options?
eminiasty
wskazany przez ciebie przyklad nie rozwiazuje klopotu
bostaf
Cytat(eminiasty @ 2.06.2017, 18:54:57 ) *
wskazany przez ciebie przyklad nie rozwiazuje klopotu

Wrzuć na fiddle'a jak to zrobiłeś. Lukniemy.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.