【问题标题】:in Ember how to pass in a parameter with link-to and use it in the rendered template?在 Ember 中,如何通过链接传递参数并在呈现的模板中使用它?
【发布时间】:2014-06-06 18:41:24
【问题描述】:

我必须链接呈现相同模板但它们具有不同标签的链接。根据用户单击的链接,我想在渲染的模板上显示不同的文本。有没有办法做到这一点?

{{link-to "new_post"}}

在我的 new_post.hbs 中我想使用这个参数。假设参数名称为isValid

{{#if isValid}}
  <h3> This is valid </h3>
{{else}}
  <h3> This is not valid </h3>
{{/if}}

我该怎么做?

谢谢!

【问题讨论】:

    标签: ember.js link-to


    【解决方案1】:

    这是你要找的吗?

    http://emberjs.com/guides/routing/query-params/#toc_link-to-helper

    您可以使用以下语法将查询参数添加到链接:

    {{#link-to 'posts' (query-params direction="asc")}}Sort{{/link-to}}
    

    【讨论】:

    • 是的,谢谢。但这给了我一个错误。我搜索了一下,发现这是 Ember 中的一个错误。
    • 您可能会收到错误消息,因为查询参数目前是一项实验性功能。您需要 Ember 的“金丝雀”版本才能使用它们,并打开“query-params-new”功能标志。此链接将进一步解释:emberjs.com/guides/configuring-ember/feature-flags
    猜你喜欢
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    相关资源
    最近更新 更多