2017-07-25 77 views
1

在Aurelia中,我創建了一個作爲容器進行交互的自定義​​元素。此容器在子節點周圍創建一些UI元素。在aurelia視圖中動態命名多個插槽

這些自定義元素可以在任何視圖中使用如下:

<wizard-container ref="container"> 
    <wizard-step title="Step 1" view-model="step1"></wizard-step> 
    <wizard-step title="Step 2" view-model="step2"></wizard-step> 
    <wizard-step title="Step 3" view-model="step3"></wizard-step> 
</wizard-container> 

wizard-container類我看了所有的孩子喜歡這個@children('wizard-step') steps = [];和循環在他們的模板:

... 
<div class="step" repeat.for="step of steps"> 
    <slot name="step-${$index}"><p>slot-${$index}</p></slot> 
</div> 
... 

的問題是插槽不會被創建。

我也不能任意元素添加到這些插槽這樣

<template slot="slot-${idx}"> 
    <p>hello world</p> 
</template> 

根據這一blog post從2016年5月的數據綁定到槽的name屬性和對slot屬性不能正常工作。

有人知道現在是否有可能或有任何解決方法的想法嗎?

回答

1

不幸的是,這是不可能的插槽。由於Shadow DOM規範的限制,不太可能。

你可以看看更換的部件,看是否可以做你需要做什麼:http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/cheat-sheet/9

向下滾動一點,你會看到在更換部件的一些信息。話雖如此,我不確定這是否適合你。我從來沒有嘗試過使用動態命名的模板部分。

+0

令人遺憾的是,動態命名的模板部件無法正常工作。必須找到另一個解決方案。謝謝 – iocast

+0

@iocast命名模板部件正常工作。看看這個問題https://stackoverflow.com/questions/44402632/in-aurelia-can-a-slot-be-used-in-a-repeat-for-binding/44405040 –

+0

法比奧,那不顯示動態命名的模板部分 –