How to render component/helper by name from instance field?

吃可爱长大的小学妹 提交于 2019-12-02 08:49:14

问题


Is there way to use component from controller/view field

So instead of using

{{contact-select label="Label:" contacts=form.prop}}
// or
{{input-field label="Label:" contacts=form.prop}}
// or
{{datepicker-component label="Label:" contacts=form.prop}}

use some like

{{context.helperName label="Label:" contacts=form.prop}}

I try use ember-helpers-render-component but it doesn't take component name from property


回答1:


You can use the component helper that was introduced in 1.11.0. Unfortunately there was no built-in way to do it before 1.11.0. If you're not able to upgrade, this thread can point you in the direction of writing your own helper.




回答2:


At version 1.11 there are component helper

for early versions i found relative question / answers: How to dynamically load ember components by name in a template? how can I invoke an ember component dynamically via a variable?

For my goals i adapt code so

https://github.com/vvs-code/ember-render-helper

and now i can use in my template

{{renderComponent field.type _param=field.value label=field.label}}

to get the same as

{{input field.value label=field.label}}

P.S> as variat - it possible get code from https://github.com/emberjs/ember.js/pull/10093 and port it into project directly



来源:https://stackoverflow.com/questions/29412559/how-to-render-component-helper-by-name-from-instance-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!