-
-
Save Gaurav0/eb11e7132b381b2804d8 to your computer and use it in GitHub Desktop.
debounced search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle', | |
queryParams: ['query'], | |
query: null, | |
queryField: Ember.computed.oneWay('query'), | |
watchSearch: function() { | |
Ember.run.debounce(this, this.runSearch, 400); | |
}.observes('queryField'), | |
runSearch: function(){ | |
this.set('query', this.get('queryField')); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a demonstration of how to create a search field in Ember. | |
Results update 400ms after the user stops typing (for a nicer search experience). That's what the debounce does. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var words = Ember.String.w("Lorem ipsum dolor sit amet consectetur adipisicing elit Ab illum labore quis ipsam voluptate sunt reprehenderit iure nisi sit ut inventore illo porro Eveniet odio sed corporis distinctio tempore temporibus".toLowerCase()); | |
export default Ember.Route.extend({ | |
queryParams: { | |
query: { | |
// Opt into full transition | |
refreshModel: true | |
} | |
}, | |
model: function(params) { | |
if (!params.query) { | |
return words; // no query; | |
} | |
var regex = new RegExp(params.query.toLowerCase()); | |
return words.filter(function(word) { | |
return regex.exec(word); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.6.2", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.1/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment