html-table - 自定义元素如何拥有多个组件
问题描述
我想创建一个<table>
,其中多个自定义元素可以有多个<tr>
组件。
我尝试使用containerless
,但元素在<table>
.
<table>
<thead>
<tr>
<th>Position</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<order-line repeat.for="line of lines" line.to-view="line" containerless></order-line>
</tbody>
</table>
自定义元素看起来像
<template>
<tr>
<td>${line.position}</td>
<td>${line.name}</td>
</tr>
<tr if.to-view="detailsVisible">
<td colspan="2">${line.complicatedDescription}</td>
</tr>
</template>
如何<tr>
在一个 aurelia CustomElement 中获取包含详细信息的表格行作为另一个元素?
解决方案
这是 html 规范的限制。一个<table>
元素不能包含除<tbody>
,<tr>
等以外的元素。
您可以使用as-element
来克服此限制:
<tr as-element="order-line" repeat.for="line of lines" line.to-view="line" containerless></tr>
这告诉模板编译器这<tr>
实际上是一个order-line
自定义元素,并对其进行处理。同时,它“愚弄”浏览器认为这只是一个普通的<tr>
推荐阅读
- r - 如何仅将引文(使用 BibTex)放在最后一章(而不是在每章的末尾)?
- html - 我的网站对移动设备不友好,只有滑块没有响应,我想让滑块响应,
- css - rollup 'rollup-plugin-postcss' 不要将 css 注入头部
- azure - 无法让 cloudtor:azure Docker 插件与最新版本的 Docker/插件一起使用
- mysql - 如何根据逻辑自查表并添加列?
- java - 为什么赋值运算符链过程以从右到左的顺序进行
- reactjs - 通过 netlify 部署反应应用程序时出现问题 - 环境变量
- authentication - 如何找出单点登录从 Google 和 Facebook 收集了哪些数据?
- angular - API Rest wordpress 上的 Angular HttpClient
- reactjs - ReactJS+Typescript:为什么React.Component中需要State类型