2015-10-16 53 views
-2

在某些處理結束時,我想要一組要渲染到屏幕上的組件陣列。呈現接受不同參數的餘燼組件陣列

所以,我想我可以做這樣的事情:

const someComponent = SomeComponent.create({ 
param1: 'something', 
param2: 'something else' 
}); 
this.get('myComponents').pushObject(someComponent); 

然後

{{#each myComponents作爲|成分|}} // 使這些莫名其妙 {{/每} }

我不能使用component幫手,因爲我有許多不同的組件,它們都接受不同的參數。

+0

是否有可能將所有參數折成attrs對象,然後使用組件助手? –

回答

0

也許在處理結束時,您可能會有一組數據而不是一組組件數組。數據可能包含某些方式讓您決定哪些組件應該用於模板中的數據,以及要使用的參數。然後,假設您擁有多個不同可能的組件,您可以根據類型在模板中有條件地渲染它們。

{{#each myComponentData as |data|}} 
    {{#if data.isDate}} 
     {{date-picker default=data.defaultDate}} 
    {{/if}} 
    {{#if data.isSomeOtherType}} 
     {{component-for-other-type param1=data.relevantParameter}} 
    {{/if}} 
{{/each}} 
+0

是的,這是我目前正在做的 - 我想知道是否有更好的方法,因爲列表變得非常大。 – jax