0
テーブルの列と行の要素が動的にバインドされる角度4を使用してプロジェクトのカスタムデータテーブルを作成しています。私は、typescriptファイルの列名の変数を作成しました。テーブルの行にデータを動的にロードする方法4
columns = [
{ key: 'Username', title: 'User Name', isSortable: true },
{ key: 'FullName', title: 'Full Name', isSortable: true},
{ key: 'Email', title: 'Email', isSortable: true}
];
コンポーネントからのサービスコールを使用して表が移入されました。
constructor(private employeeService: EmployeeService, private router: Router) {
this.Employee = [];
}
private populateEmployee() {
this.employeeService.getPagedEmployees(this.query).subscribe(Result => {
this.Employee = <IEmployeeInterface[]>Result["data"],
this.query.totalItems = Result["count"]
});
}
これは、「角度サービス」機能から従業員を呼び出します。
getPagedEmployees(filter): Observable<IEmployeeInterface[]> {
var jsonString = JSON.stringify(filter);
return this.http.get(this.baseUrl + 'GetEmployeeUrl').map((response: Response) => {
return response.json();
})
.catch(this.handleError);
}
テンプレートファイルにデータテーブルをバインドしようとしています。ここでは従業員がIEmployeeInterface
IEmployeeInterfaceがexport interface IEmployeeInterface {
Id: number,
username: string,
fullname: string,
email: string
}
ある
Employee: IEmployeeInterface[];
の配列である私は、データを結合していたテーブルはこのようなものです。
<table class="table table-bordered table-striped table-hover dataTable">
<tr>
<th *ngFor="let c of columns">
<div *ngIf="c.isSortable" (click)="SortBy(c.key)">
{{ c.title }}
<i *ngIf="query.sortBy === c.key" class="fa"
[class.fa-sort-asc]="query.isSortAscending"
[class.fa-sort-desc]="!query.isSortAscending">
</i>
</div>
<div *ngIf="!c.isSortable">
{{ c.title }}
</div>
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of Employee" >
<td *ngFor="let column of columns">
{{data[column.key]}}
</td>
</tr>
</tbody>
</table>
{{data [column]}}は空の値を返します。 Columnヘッダーが正しく表示されます。 私はここからの方法を試してみましたが、それはあなたが書くの角度4. Dynamically loading columns and data into tables in angular 2
これはAngularに関連しているようには見えませんが、 'data [column]'には値が含まれていません。私は、最初の2つのコードスニペットが質問やその部分にどのように関連しているのか分からず、3番目のコードを切り捨てた '
'が表示されています。私たちが見る必要があるのは、 '従業員'と 'dcolumn 'の内容です。 –謝罪します。私はその問題を修正した。私はそれを直接修正できるかどうか、または編集タグを追加する必要があるかどうかはわかりません。これは "dcolumn"ではなく "columns"です。私は{{data [column.key]}}のようなものを各列の各行にある従業員からバインドするようにします。 –
これはうまくいくはずですが、あなたの質問には従業員に含まれるデータは表示されません。 –
答えて
では動作しませんでした:あなたが投稿
コードが
dcolumn
を定義していません。可能性がありますdcolumn
未定義ですか?または、string[]
以外のものがありますか?出典
2017-08-29 12:30:12 meriton
"dcolumn"ではなく "columns"です。私は{{data [column.key]}}のようなものを各列のEmployeeからのデータを各行にバインドしたいと思っています。私は質問を更新しました。謝罪いたします。 文字列[]形式で列名を入れようとしましたが、それはどちらも動作しません。 –
関連する問題