在Ember.js中组合linkTo和action助手 [英] Combine linkTo and action helpers in Ember.js
问题描述
我需要在Ember.js中组合linkTo和action helpers。我的代码是:
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>
To:
<li>
{{#link-to 'support' {{action 'myAction' 'support'}} }}Support{{/link-to}}
</li>
如何实现?
检查我的答案 Ember 2.0兼容 ,对于SEO解决方案。
推荐答案
Ember Link Action addon
最近我开发了这个插件,以便与 Ember 2.0 - 2.14+兼容( 1.13也可以!)的风格和利用关闭操作/动作名称。 SEO可以这样做
Ember Link Action addon
I've developed this addon recently to address this with Ember 2.0 - 2.14+ compatible (1.13 also works!) style and taking advantage of closure actions/action names. This is OK for SEO!
ember install ember-link-action
用法
您可以将 invokeAction
param绑定到 {{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}}
您还可以使用动作名称而不是关闭操作:
You can also use action name instead of closure action:
{{#link-to 'other-route' invokeAction='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 2版本。
Compatibility
Automated test suite confirms that addon works with 1.13 up to latest Ember 2 releases.
它适用于Ember的发行版,测试版和经销版本。
It works with a release, beta and canary versions of Ember.
Addon GitHub信息库欢迎您的贡献。
这篇关于在Ember.js中组合linkTo和action助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!