angular5 - 基于列名的下拉列表中的表数据
问题描述
我有一个这样的模拟数据:
export const CHARACTERS: any[] =
[
{
name: 'Earl of Lemongrab',
age: 'Unknown',
species: 'Lemon Candy',
occupation: 'Earl, Heir to the Candy Kingdom Throne'
},
{
name: 'Bonnibel Bubblegum',
age: '19',
species: 'Gum Person',
occupation: 'Returned Ruler of the Candy Kingdom'
},
{
name: 'Phoebe',
age: '16',
species: 'Flame Person',
occupation: 'Ruler of the Fire Kingdom'
}
我已经获取了这些数据并将其显示在表格上。现在我想根据列名在下拉列表中显示所有这些数据。
我正在使用下面的代码,但它没有正确显示;
<div class = "two">
<select [(ngModel)]="searchText" name="char[column]" placeholder="select">
<option
*ngFor="let char of characters"
*ngFor="let column of columns"
[ngValue]="char[column]">{{char[column]}}</option>
</select>
</div>
我也尝试过下面的代码,但它给了我一个错误,说名称不是列的已知属性。虽然我的专栏有四个字符串,例如 ["name" , "age" , "species" , "gender"]
<div class = "two">
<select [(ngModel)]="searchText" name="column" placeholder="select">
<option
*ngFor="let column of columns"
value="column.name">{{column.name}}</option>
</select>
</div>
解决方案
<div class = "two">
<select [(ngModel)]="searchText" name="char[column]" placeholder="select">
<option
*ngFor="column of columns"
Value="char[column.name]">{{char[column.name]}}</option>
</select>
</div>
推荐阅读
- python - Queue.asyncio ValueError: task_done() 调用了太多次 - 编码错误或检测到错误?
- jquery - 在select2 jquery中选择后如何将数据设置到表中
- javascript - 制作响应式导航栏
- python - 如何通过与 SQLAlchemy 的关系支持 ManyTableToManyTable?
- ios - Swift - 一旦日期过去,将数据从一个 TableViewController 传输到另一个
- java - 使用递归的第一个计时器
- field - micronaut 多值表单字段支持?
- c++ - 这个 C++ 隐式转换是如何发生的?
- html - 在 Bootstrap 中减少内容之间空间的最简洁方法
- java - 我想使用注释 @ComponentScan 但我收到错误“考虑定义类型的 bean”SpringBoot 2.1.0.RELEASE