2017-03-07 17 views
0

我想有條件地創建一個HTML節點的綁定。如何有條件地創建HTML節點的綁定?

@dom def maybeEmpty: Binding[Node] = { 
    if (math.random > 0.5) { 
    <div>non-empty content</div> 
    } 
} 

但是代碼不能編譯。

error: type mismatch; 
found : Unit 
required: org.scalajs.dom.raw.Node 

回答

-1

你需要一個else塊用空的內容,通常是一個HTML註釋:

@dom def maybeEmpty: Binding[Node] = { 
    if (math.random > 0.5) { 
    <div>non-empty content</div> 
    } else { 
    <!-- empty content --> 
    } 
} 
相關問題