javascript - Accessing nested route parameter from parent route/template -
i have nested route behaves less-nested version of itself:
/code/class/myfile.java /code/coverage/:coverageid/class/myfile.java
somewhat self-explanatory, coverage
route decorates page additional highlighting/details not present in "normal" version.
however, code
template defines sidebar includes navigation tree access other code files. when viewing /coverage/
page, sidebar display links differently, ensuring nested route maintained when clicking around.
my problem:
i can't seem find way access :coverageid
in code
route or template modify way links displayed. code route:
export default ember.route.extend({ model(params) { console.log('coverage id: ' + params.coverageid); ...
prints undefined
. seems make sense since it's child parameter, "out of scope"?
my incorrect solution:
i tried in class
route:
export default ember.route.extend({ model(params) { var parentmodel = this.modelfor('code'); parentmodel.coverageid = params.coverageid; ...
which, in code.hbs
template:
{{#if model.coverageid}} {{#link-to 'code.coverage.class' model.coverageid filename}}{{filename}} {{/link-to}} {{else}} {{#link-to 'code.class' filename}}{{filename}}{{/link-to}} {{/if}}
actually works! link produced when viewing coverage
route.
however: while can right-click of these links open them in separate tab successfully, if regularly click them, receive error:
error: assertion failed: must use ember.set() set `coverageid` property (of [object object]) `425988`
but of course, can't use parentmodel.set('coverageid', params.coverageid);
, because fails with:
typeerror: parentmodel.set not function
so! how can either (1) examine nested route parameters in parent (code
) route, or (2) inject known value (:coverageid
) child route into parent?
you rid of .set
not function error using global ember.set
.
so, instead of:
parentmodel.coverageid = params.coverageid;
try:
ember.set(parentmodel, 'coverageid', params.coverageid);
Comments
Post a Comment