2017-06-07 43 views
2

我想創建一個自定義元素,循環遍歷一個數組,並將其應用於數組中的每個項目。例如,定製元素的視圖模板將包含這樣的:在Aurelia中,是否可以在repeat.for綁定中使用插槽?

<div repeat.for="i of items"> 
    <div with.bind="i"> 
    <slot></slot> 
    </div> 
</div> 

當我除去repeat.for和with.bind屬性,所述槽將顯示一個單一的時間。有沒有辦法讓列表中的每個項目都重複一遍?

回答

4

不,您不能在今天使用repeat.forbind的插槽。要做到這一點,你必須使用可更換部件。例如:

<div repeat.for="i of items"> 
    <div with.bind="i"> 
    <template replaceable part="content"></template> 
    </div> 
</div> 

用法:

<my-component> 
    <template replace-part="content">Some Content - ${somePropertyOfI}</template> 
</my-component> 

Runnable的例子:https://gist.run/?id=29aa1c1199f080c9ba0e72845044799b

+0

的奧裏利亞博客http://aurelia.io/blog/2016/05/23/aurelia-shadow-dom -v1-slots-prerelease/says「以上所有內容都是使用Aurelia實現的,它還可以與模板控制器一起使用,比如if和repeat,它們可以動態地生成內容我們已經修復了我們的@ child和@ children裝飾器來理解新的模型「。但它似乎不起作用 –

+0

@MosèBottacini在這個答案的時候,它不可能與''一起使用'pepe'或'bind'。向我解釋你想要做什麼,我會試着給你一個解決方案 –

+0

只是表示可能文檔不同步,因爲它明確指出它可以完成 –

相關問題