ember.js - How to work with global query params -


i have query params don't want loose when switch 1 route another. docs, solution seems use of global query params, set on applicationcontroller.

let's setup :

  • a page list of objects displayed , criterias on left filter list. may call related controller listcontroller. criterias have query params.
  • when object first page clicked, whole page replaced detailed view of object. page need able go filtered list , consequently keep query params.

i need access applicationcontroller's global query params listcontroller manipulations. it's easy :

app.listcontroller = app.arraycontroller.extend({    needs: "application",    qp: ember.computed.alias("controllers.application"),    .... 

when criteria changes, filtering operation done server side, need refresh listroute when query params changes.

how applicationroute ?

app.applicationroute = ember.route.extend({    actions: {       queryparamsdidchange: function () {          var listroute = ??????;          listroute.refresh();       }    } } 

what think of whole setup ? on path ? i'm not sure...

this did.

the queryparams defined in route. "parent", implications children.

queryparams:   fooparam:      refreshmodel: true 

setting refreshmodel: true trigger beforemodel:, model:, , aftermodel: hooks route descendant routes. currently, there no way individually turn on or off behavior descendants.

and controller

queryparams: ['fooparam'] fooparam: null 

queryparams hook in controller not override queryparams hook in route, rather, necessary , complementary entire functionality work. should not put of these belonging in controller in route, or belongs in route in controller.

all query parameter keys need defined in controller well. value of hook default value. still change according query parameter.

then, descendant route,

model: ->   this.modelfor('parent').filterby('childattribute', this.paramsfor('parent').fooparam) 

or if want 1 (the first default) record:

model: ->   this.modelfor('parent').findby('childattribute', this.paramsfor('parent').fooparam) 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -