相关疑难解决方法(0)

Knockout 3.2:组件/自定义元素可以包含子内容吗?

我可以创建在其中使用子标记的非空Knockout组件吗?

一个示例是用于显示模式对话框的组件,例如:

<modal-dialog>
  <h1>Are you sure you want to quit?</h1>
  <p>All unsaved changes will be lost</p>
</modal-dialog>
Run Code Online (Sandbox Code Playgroud)

其中与组件模板一起:

<div class="modal">
  <header>
    <button>X</button>
  </header>

  <section>
    <!-- component child content somehow goes here -->
  </section>

  <footer>
    <button>Cancel</button>
    <button>Confirm</button>
  </footer>
</div>
Run Code Online (Sandbox Code Playgroud)

输出:

<div class="modal">
  <header>
    <button>X</button>
  </header>

  <section>
    <h1>Are you sure you want to quit?</h1>
    <p>All unsaved changes will be lost</p>
  </section>

  <footer>
    <button>Cancel</button>
    <button>Confirm</button>
  </footer>
</div>
Run Code Online (Sandbox Code Playgroud)

knockout.js knockout-components

3
推荐指数
1
解决办法
1508
查看次数

标签 统计

knockout-components ×1

knockout.js ×1