2015-03-03 59 views
4

我想是這樣的:是否有可能有嵌套淘汰賽組件在JavaScript

<base-component> 
    <sec-component> 
    </sec-component> 
</base-component> 

是否有可能與基因敲除組件的幫助,以實現這一目標?

+0

從[文檔】(http://knockoutjs.com/documentation/component-overview.html):_ ...可以由一起(嵌套的)或從其他components_ – janfoeh 2015-03-03 11:31:21

+0

顯示升值繼承通過投票/接受。公告不屬於問題(沒有分心,沒有閒聊(閱讀幫助→[tour](http://stackoverflow.com/tour)) – Anthon 2015-03-06 07:43:05

回答

7

是的。在本文檔中,「傳遞標記成組件」部分:http://knockoutjs.com/documentation/component-custom-elements.html#passing-markup-into-components

<!-- This could be in a separate file --> 
<template id="my-special-list-template"> 
    <h3>Here is a special list</h3> 

    <ul data-bind="foreach: { data: myItems, as: 'myItem' }"> 
     <li> 
      <h4>Here is another one of my special items</h4> 
      <!-- ko template: { nodes: $componentTemplateNodes, data: myItem } --><!-- /ko --> 
     </li> 
    </ul> 
</template> 

<my-special-list params="items: someArrayOfPeople"> 
    <!-- Look, I'm putting markup inside a custom element --> 
    The person <em data-bind="text: name"></em> 
    is <em data-bind="text: age"></em> years old. 
</my-special-list> 

li元件內部的ko template,節點將被添加。

因此,您也可以在的內部標記中插入不同的組件。例如:

<!-- This could be in a separate file --> 
<template id="my-special-list-template"> 
    <h3>Here is a special list</h3> 

    <ul data-bind="foreach: { data: myItems, as: 'myItem' }"> 
     <li> 
      <h4>Here is another one of my special items</h4> 
      <!-- ko template: { nodes: $componentTemplateNodes, data: myItem } --><!-- /ko --> 
     </li> 
    </ul> 
</template> 

<template id="my-person-template"> 
    The person <em data-bind="text: name"></em> 
    is <em data-bind="text: age"></em> years old. 
</template> 

<my-special-list params="items: someArrayOfPeople"> 
    <my-person></my-person> 
</my-special-list>