Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass array to linkTo helper

Tags:

ember.js

I want to create a component which needs to generate dynamics links. I tried passing the link data as an array, but this does not work.

var user1 = get("store").find("user", 1);
var data = {link: ["users.show", user1], title: "User1"};

{{#link-to data.link}}{{data.title}}{{/link-to}}

This should be equal to

{{#link-to "users.show" 1}}{{data.title}}{{/link-to}}

How to generate fully dynamic links from a variable?

like image 819
gucki Avatar asked Nov 17 '13 22:11

gucki


1 Answers

You can specify an array as params argument into a link-to helper. Similar to nickiaconis' answer answer, but with just the default {{link-to}} helper:

{{#link-to params=data.link}}{{data.title}}{{/link-to}}

...will render something like:

<a href="/users/show/1">User1</a>

(tested with Ember 2.3.0)

like image 50
cspanring Avatar answered Sep 19 '22 03:09

cspanring