Ember js,HTMLbars:使用组件作为组件的参数

时间:2016-06-01 13:32:50

标签: ember.js htmlbars

我想要这样的事情:

{{component-one title=(component-two paramX paramY)}}

组件助手在这里不起作用,我试过这个

{{component-one title=(component 'component-two' params)}}

我也尝试过帮助渲染我的组件但失败了。似乎我发现的所有答案都已经过时了 how can I invoke an ember component dynamically via a variable?

更具体我的用例。我使用tooltipster并希望使用按钮init来渲染工具提示。

{{#tool-tipster title=(my-comp params) ... }}

------更新---------

问题是,我最终需要一个标题的HTML字符串,带有一个按钮和一个data-ember-action。我无法使用包装器组件的tpl。如果我扩展工具提示,它看起来像这样:

export default TooltipsterComponent.extend({
  title: 'title as html string'
  //other tooltipster options go here with "optionname: optionvalue"
});

所以我已经想到了这样的事情:

title: function() {
  //load component and return rendered component by hand
}}

但这让我回到了我的问题,即我无法手工渲染任何组件。

每次输入的Thx!

干杯 裨

-----更新-------

altrim on gitbub为我提供了问题的确切解决方案:https://github.com/altrim/tooltipster-content-component

2 个答案:

答案 0 :(得分:2)

您可以执行此操作,但需要使用组件帮助程序两次:

首先传递组件:

{{wrap-component child=(component 'pass-component' name="blah")}}

接下来在wrap-component.hbs内调用组件:

{{component child}}

结帐ember-twiddle

答案 1 :(得分:1)

使用title=(component 'component-two' params)是正确的想法,但我非常肯定你不能在组件助手中使用位置参数而不是解析名称..所以你需要做相反:title=(component 'component-two' params=params)

如果要在component-one内渲染该组件,则需要再次使用组件助手:{{component title}}

这至少是我如何让它发挥作用..我相当有信心它是" ember"这样做的方法。

相关问题