我想要做的是將字符串傳遞給{{component}}
幫助程序,但我希望更多地控制它在運行時傳入的字符串。Ember - 擴展{{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問題顯示您可以擴展一個,但我找不到Ember中幫助器位於component
的位置。似乎也沒有任何關於擴展現有幫助者的問題/文檔。這是我會用這種方法做的。
// 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](https://flexi.readme.io/docs) – Lux
Flexi是一個UI框架。我的問題與此無關。 – CookieMonster
Flexi正在解決您想要的任務:如何爲同一個組件創建多個佈局。所以也許它可以幫助你檢查他們是如何解決這個問題的。只是想指出你,對不起。我認爲這對你很有趣。 – Lux