Is it possible #linkTo route with two dynamic segments using 'this'?

I implemented a solution for a route with several dynamic segments , where one of the models is an array.

An implementation can be found here .

Basically, a router is defined as follows:

App.Router.map(function() { this.resource("ab", { path: "/:a/:b" }); }); 

When you go to this route, a used as is, and b converted to an array. Both "models" are passed to their respective controllers, which also turn the template into a named socket for the application template.

Now I would like to use helper #linkTo in a template that displays an array. To make this work, somehow I would need to combine {{this}} and the current value of a into one object.

Then the idea is to do something like this for this template:

 <script type="text/x-handlebars" id="b"> Template b: {{#each model}} {{#linkTo ab {a: {{this}}, b: controller.content} }} {{this}} {{/linkTo}} {{/each}} </script> 

Is this possible, or are there alternatives?

+4
source share
1 answer

You can pass multiple arguments to linkTo . This also works with nested routes. Ember walks through the tree of nested routes and sets models for him accordingly.

 {{#linkTo 'ab' ab}}Foo{{/linkTo}} 

Where a and b are models that can be resolved inside this template.

Edit: leave a comment

You need a custom serialize method that transforms the model into an object with keys corresponding to the identifiers defined on the route. The serialize method is used by linkTo to build the route.

 serialize: function(model) { return { a: model.get('a'), b: model.get('b') }; } 

Note. On the model hook for the resource route, you will need to use the same keys from the params hash to perform the search. This is used when the user directly visits the URL instead of linkTo .

See this jsbin example.

+4
source

Source: https://habr.com/ru/post/1492983/


All Articles