使用ember的link-to helper根据计算属性链接到不同的页面

时间:2021-10-03 21:10:12

I would like a certain link on my handlebars page to dynamically change based on a computed property that I have in the page's javascript file.

我希望我的把手页面上的某个链接根据我在页面的javascript文件中的计算属性动态更改。

I discovered a feature of handlebars called Subexpressions but it doesn't seem to allow you to insert a computed property into the middle of a handlebars link-to expression, which would be a simple way of accomplishing what I'm trying to do. The more I look it seems like this may not be possible with vanilla ember.js handlebars helpers, but I figured I should ask here first.

我发现了一个名为Subexpressions的把手功能,但它似乎不允许你将一个计算属性插入到把手链接到表达式的中间,这将是完成我想要做的事情的一种简单方法。我看起来越多,似乎这可能不可能与vanilla ember.js车把助手,但我想我应该先问这里。

Thanks.

1 个解决方案

#1


0  

Yes. You can directly include computed property in link-to helper.

是。您可以直接在link-to helper中包含计算属性。

{{#link-to anyComputedProperty }} Reports {{/link-to}}

Even you can include subexpressions for generating routes for link-to helper.

即使您可以包含子表达式来生成链接到帮助程序的路由。

{{#link-to (concat 'new' anyComputedProperty) }} Reports {{/link-to}}.

As torazaburo mentioned in comments, you can invoke actions to route/controller and from there you can use transitionTo/transitionToRoute method respectively.

正如在评论中提到的torazaburo,您可以调用路由/控制器的操作,并从那里分别使用transitionTo / transitionToRoute方法。

#1


0  

Yes. You can directly include computed property in link-to helper.

是。您可以直接在link-to helper中包含计算属性。

{{#link-to anyComputedProperty }} Reports {{/link-to}}

Even you can include subexpressions for generating routes for link-to helper.

即使您可以包含子表达式来生成链接到帮助程序的路由。

{{#link-to (concat 'new' anyComputedProperty) }} Reports {{/link-to}}.

As torazaburo mentioned in comments, you can invoke actions to route/controller and from there you can use transitionTo/transitionToRoute method respectively.

正如在评论中提到的torazaburo,您可以调用路由/控制器的操作,并从那里分别使用transitionTo / transitionToRoute方法。