在 Ember.js 中结合 linkTo 和动作助手 [英] Combine linkTo and action helpers in Ember.js

查看:26
本文介绍了在 Ember.js 中结合 linkTo 和动作助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Ember.js 中结合 linkTo 和 action helper.我的代码是:

I need to combine linkTo and action helpers in Ember.js. My code is:

{{#link-to 'index'}}<span {{action 'clear'}}>Clear</span>{{/link-to}}

但我想让它像这样:

{{#link-to 'index' {{action 'clear'}} }}Clear{{/link-to}}

还有:

<li>
    {{#link-to 'support'}}
        <span {{action 'myAction' 'support'}}>Support</span>
    {{/link-to}}
</li>

致:

<li>
    {{#link-to 'support' {{action 'myAction' 'support'}} }}Support{{/link-to}}
</li>

我怎样才能做到这一点?

How can I achieve this?

检查我对Ember 2.0 兼容的回答,SEO 解决方案可以.

推荐答案

Ember Link Action addon

这是SEO 解决方案的好方法

ember install ember-link-action

用法

您可以将闭包动作作为 invokeAction 参数传递给 {{link-to}} 组件:

Usage

You can pass closure action as invokeAction param to {{link-to}} component:

{{#link-to 'other-route' invokeAction=(action 'testAction')}}
  Link to another route
{{/link-to}}

要将参数传递给操作,您可以使用:

To pass parameters to action you can use:

{{#link-to 'other-route' invokeAction=(action 'testAction' param1 param2)}}
  Link to another route
{{/link-to}}

兼容性

自动化测试套件确认插件适用于 1.13 至最新的 Ember 3 版本.

Compatibility

Automated test suite confirms that addon works with 1.13 up to latest Ember 3 releases.

它适用于 Ember 的发行版、测试版和金丝雀版本.

It works with a release, beta and canary versions of Ember.

Addon GitHub 存储库. 欢迎投稿.

这篇关于在 Ember.js 中结合 linkTo 和动作助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆