Skip to content

Instantly share code, notes, and snippets.

@tkh44
Last active December 21, 2015 23:38
Show Gist options
  • Select an option

  • Save tkh44/6383141 to your computer and use it in GitHub Desktop.

Select an option

Save tkh44/6383141 to your computer and use it in GitHub Desktop.
search ion
search: _.debounce(function(e) {
var self = this,
$noResults = this.$('.empty-state'),
$loading = this.$('.loading-state'),
contacts = Mast.data.contacts,
value = $.trim(e.currentTarget.value),
data;
if (value.length < 1) {
self.collection.reset();
self.afterReset();
} else {
data = {
search: value
};
// Clear out the previous results and show the loading state
this.autoCompleteItems.empty();
$noResults.hide();
$loading.show();
self.collection.fetch({
data: data,
reset: true,
success: function(child, collection, req) {
contacts.getContacts(data.search, function() {
if (contacts.length) {
self.collection.add(contacts.toJSON());
}
self.afterReset();
});
}
});
}
}, 300),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment