gpt4 book ai didi

ember.js - EmberJS - 如何使用 linkTo 动态生成链接?

转载 作者:行者123 更新时间:2023-12-04 15:24:05 26 4
gpt4 key购买 nike

有没有办法使用 link-to 动态生成链接通过传递带有路径路径的变量来帮助?

例如,不要像这样对路径进行硬编码:

{{#linkTo "route.subroute" model}}{{model.title}}{{/linkTo}}

我希望能够通过 link-to helper 一个保存路径的变量,如下所示:
{{#linkTo destination model}}{{model.title}}{{/linkTo}}

这样做的用例是允许我合并仅在此路径上有所不同的模板。例如,如果有两个集合,每个集合都有不同的目的地。当使用每个帮助程序呈现时,除了 link-to 中的路径外,模板是相同的。 .

如果我可以将这个变量保存在 View 的 Controller 中并传递它,我就可以为两个列表只使用一个模板。

我想过手动构建这样的路径:
<a {{bindAttr href="destination"}}>{{model.title}}</a>

但这没有与路由器的集成来确定我需要的事件状态。

最佳答案

Is there a way to dynamically generate a link using the linkTo helper by passing a variable with the route path?



现在不行。

The use case for this is to allow me to consolidate templates which only differ by this path. For instance, if there are two collections each with a different destination.



同意这是一个有效的用例,我希望 linkTo helper 将来支持它。同时,由于您只有两个集合,因此您可以使用模板中的条件来完成此操作
{{#if isRouteOne}}
{{#linkTo "routeOne.subrouteOne" model}}{{model.title}}{{/linkTo}}
{{else}}
{{#linkTo "routeTwo.subrouteTwo" model}}{{model.title}}{{/linkTo}}
{{/if}}

关于ember.js - EmberJS - 如何使用 linkTo 动态生成链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16021148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com