Saturday 15 March 2014

javascript - I want Ember.js' {{input value="searchTerm"}} to set its value to ' ' when the URL changes -



javascript - I want Ember.js' {{input value="searchTerm"}} to set its value to ' ' when the URL changes -

i'll seek simplify problem much possible,

but need handlebar.js' {{input value="searchterm"}} set value of searchterm 'null' every time url changes.

the input described above meant auto filter list on same page. typing in input automatically updates value of 'searchterm' whatever typed

the value searchterm defined in action named searchresults

this property in controller:

searchresults: function() { var searchterm = this.get('searchterm'); var regexp = new regexp(searchterm, 'i'); // utilize `this.filter` because contents of `this` array of objects var filteredresults = this.filter(function(category) { homecoming regexp.test(category.get('categoryname')); }); homecoming filteredresults; }.property('@each.categoryname', 'searchterm'),

so break downwards need:

regardless of current value of searchterm is, needs set ' '. setting value of searchterm ' ' occurs when page transitions

this can done on route via didtransition or willtransition event handlers. routes have reference controller (via this.controller), , still though controllerfor (e.g.: var c = this.controllerfor('controllername'); could this:

app.someroutethaterasesthesearchtermroute = ember.route.extend({ actions: { // implement didtransition. no arguments didtransition tho didtransition: function() { this.controller.set('searchterm', ''); }, // or, implement willtransition willtransition: function(transition) { this.controller.set('searchterm', ''); } } });

you implement separate method gets fired on('willtransition'), maintain existing handler , append yours. create mixin other routes utilize or other routes can inherit class without breaking other custom transition handler, if any.

javascript ember.js properties ember-router

No comments:

Post a Comment