javascript - Ember.js setupController fired only once -
suppose have view:
cellarrails.searchtextfield = ember.textfield.extend({ templatename: 'index', insertnewline: function(){ this.get('controller').set('query', this.get('value')); // calling search method of application controller this.get('controller').send('search'); this.set('value', ''); } }); and applicationcontroller:
cellarrails.applicationcontroller = ember.controller.extend({ needs: ['search'], query: '', // here search method search: function() { // i'm using ember-query lib, provides helper, acts usual transitiontoroute this.transitiontoroutewithparams('search', { q: this.get('computedquery') }); }, computedquery: function() { this.get('controllers.search').set('q', this.get('query')); return this.get('query'); }.property('query') }); so should transitioned searchroute:
cellarrails.searchroute = ember.route.extend({ serializeparams: function(controller) { return { q: controller.get('q') }; }, deserializeparams: function(params, controller) { controller.set('q', params.q); }, // pass cellarrails.track model searchcontroller's context setupcontroller: function(controller, context, params) { console.log('setup controller hooked!'); controller.set('context', cellarrails.track.find(params)); } }); in cellarrails.track model have redefined find method. problem: code works, setupcontroller hook fires first time (when transition applicationroute searchroute), but if in searchroute hook doesn't fire , find method of cellarrails.track model doesn't fire too.
when setup setupcontroller on route model hook not invoked. if want both hooks model , setupcontroller should fire have call this._super(...) in setupcontroller hook maintain model hook default behaviour:
cellarrails.searchroute = ember.route.extend({ ... model: function(params) { return cellarrails.mymodel.find(); }, setupcontroller: function(controller, model) { this._super(controller, model); ... } ... }); hope helps.
Comments
Post a Comment