From efd5bbfbdef0b46dc1083a8fb8cd456a02df41d7 Mon Sep 17 00:00:00 2001 From: nat- Date: Fri, 22 Jul 2016 11:18:01 +1200 Subject: [PATCH] Stop mix up of results updating dropdown Slower Requests would update after quicker requests. so check if the request is still valid before updating the items list --- src/Typeahead.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Typeahead.vue b/src/Typeahead.vue index 5031bdc3..c107cbc2 100644 --- a/src/Typeahead.vue +++ b/src/Typeahead.vue @@ -107,6 +107,8 @@ const typeahead = { }, methods: { update() { + // store initial query + var originalQuery = this.query; if (!this.query) { this.reset() return false @@ -117,8 +119,12 @@ const typeahead = { } if (this.async) { callAjax(this.async + this.query, (data)=> { - this.items = (this.key ? data[this.key] : data).slice(0, this.limit) - this.showDropdown = this.items.length ? true : false + //when the results come back check if they are still required by checking origianl query agains current query + if(originalQuery == this.query){ + // only update items with request data if the query has not changed and is still valid + this.items = (this.key ? data[this.key] : data).slice(0, this.limit) + this.showDropdown = this.items.length ? true : false + } }) } },