我是 ember 新手,正在开发一个简单的测试应用程序。我正在尝试从 json 数据动态渲染表的行。任务比较简单。然而,每一行都是一个组件,并且 ember 将元素包装在带有 ember-view 类的 div 中。我相信这会阻止我的表格正确渲染。在 ember 中通常如何处理这个问题?
//contact-listing.hbs
<tr>
<th scope="row">{{contact.employee_id}}</th>
<td>{{contact.firstName}}</td>
<td>{{contact.lastName}}</td>
<td>{{contact.email}}</td>
<td>{{contact.telephone}}</td>
<td>{{contact.department}}</td>
</tr>
//contacts.hbs
<h1>Employees</h1>
<table class="table">
<thead>
<tr>
<th>Employee ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Telephone</th>
<th>Department</th>
</tr>
</thead>
<tbody>
{{#each model as |_contact|}}
{{contact-listing contact=_contact}}
{{/each}}
</tbody>
</table>
现在这是我返回的标记 - 在浏览器中,所有 td 数据都呈现为内联,没有表格格式。我认为这是由于插入了 ember 包装 div 造成的。
<div id="ember438" class="ember-view">
<tr>
<th scope="row"><!----></th>
<td><!----></td>
<td><!----></td>
<td><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="761c191e183615191b0617180f5815191b" rel="noreferrer noopener nofollow">[email protected]</a></td>
<td>416-555-1111</td>
<td>finance</td>
</tr>
</div>
这是视觉上呈现的内容:
最佳答案
用途:
tagName: '',
在你的组件定义中。
关于javascript - ember-view 包装器破坏了我的 table ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36484788/