【发布时间】:2017-04-12 21:29:02
【问题描述】:
我想要做的是将一个字符串传递给{{component}} 助手,但我想更好地控制它在运行时传入的字符串。
例如
// getComponentToRender will get the current UI theme in the app,
// determine whether it's running on the mobile mode, then fetches the
// appropriate name of a component to render based on the type of the
// component. Just an example.
{{component getComponentToRender(ComponentType.Button)}}
我对此进行了调查,结果证明这是不可能的(否则,请纠正我)。当然,还有computed 属性,但它不带参数。
接下来,我研究了扩展助手。 This stackoverflow 问题显示您可以扩展一个,但我找不到 component 助手在 Ember 中的位置。似乎也没有关于扩展现有助手的任何问题/文档。这就是我要用这种方法做的事情。
// I can't find where the {{component}} helper is located.
import Component from './???'
export default Component.extend({
compute(componentType, hash) {
let componentName = getComponentToRender(componentType);
this._super(componentName, hash)
}
})
我错过了什么?如果有人能把我引向正确的方向,那就太好了。
【问题讨论】:
-
也许结帐flexi
-
Flexi 是一个 UI 框架。我的问题与此无关。
-
Flexi 正在解决您想要的问题:如何为同一个组件设置多个布局。所以也许它可以帮助你检查他们是如何解决这个问题的。只是想指出你那里,对不起。我认为这对你来说会很有趣。