|
273 | 273 | query.callback(data); |
274 | 274 | }); |
275 | 275 | } else { |
276 | | - if (!opts.query && opts.ajax) { |
| 276 | + if (!("query" in opts) && opts.ajax) { |
277 | 277 | opts.query = (function () { |
278 | 278 | var timeout, // current scheduled but not yet executed request |
279 | 279 | requestSequence = 0, // sequence used to drop out-of-order responses |
|
438 | 438 | var results = this.results, |
439 | 439 | more = results.find("li.select2-more-results"), |
440 | 440 | below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible |
441 | | - offset = -1; // index of first element without data |
| 441 | + offset = -1, // index of first element without data |
| 442 | + page = this.resultsPage+1; |
442 | 443 |
|
443 | 444 | if (more.length === 0) return; |
444 | 445 |
|
445 | 446 | below = more.offset().top - results.offset().top - results.height(); |
446 | 447 |
|
447 | 448 | if (below <= 0) { |
448 | 449 | more.addClass("select2-active"); |
449 | | - this.opts.query({term: this.search.val(), page: (this.resultsPage + 1), callback: this.bind(function (data) { |
| 450 | + this.opts.query({term: this.search.val(), page: page, callback: this.bind(function (data) { |
450 | 451 | var parts = [], self = this; |
451 | 452 | $(data.results).each(function () { |
452 | 453 | parts.push("<li class='select2-result'>"); |
|
467 | 468 | } else { |
468 | 469 | more.remove(); |
469 | 470 | } |
470 | | - this.resultsPage = data.page; |
| 471 | + this.resultsPage = page; |
471 | 472 | })}); |
472 | 473 | } |
473 | 474 | }; |
|
488 | 489 | return; |
489 | 490 | } |
490 | 491 |
|
491 | | - this.resultsPage = 0; |
| 492 | + this.resultsPage = 1; |
492 | 493 | opts.query({term: search.val(), page: this.resultsPage, callback: this.bind(function (data) { |
493 | 494 | var parts = []; // html parts |
494 | 495 |
|
|
0 commit comments