2015-03-03 73 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>