0
問題是,我想要能夠選擇多個複選框,並單擊測試按鈕,在控制檯中顯示選定的框。這裏的問題是,我只使用一個顯示在幾行中的複選框。 I'm採用了棱角分明2與材料設計組件和角火2.HTML/TypeScript在角度2中顯示多個複選框值
//TypeScript
import { Component, Input, OnInit } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { DataSource } from '@angular/cdk';
@Component({
selector: 'waybill-billing',
templateUrl: './waybillbilling.component.html',
styleUrls: ['./waybillbilling.component.css']
})
export class WaybillBillingComponent implements OnInit {
checked = false;
@Input('id') waybillId: string;
displayedColumns = ['status', 'type', 'articleId', 'description', 'amount'];
dataSource: FirebaseDataSource;
constructor(private db: AngularFireDatabase){}
ngOnInit(): void {
this.dataSource = new FirebaseDataSource(this.db, this.waybillId);
}
}
export class FirebaseDataSource extends DataSource<any> {
items: FirebaseListObservable<any[]>;
constructor(private db: AngularFireDatabase, private waybillId: string) {
super();
}
connect(): FirebaseListObservable<any[]> {
this.items = this.db.list('xxx/pieces/' + this.waybillId);
console.log(this.items);
return this.items;
}
disconnect(){
}
}
//HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="script.js"></script>
<div class="example-container mat-elevation-z8">
<md-table #table [dataSource]="dataSource" class="mat-typography">
<div> ng-controller="AppCtrl">
<ng-container cdkColumnDef="status">
<md-header-cell class="body-2" *cdkHeaderCellDef> Status </md-header-cell>
<md-cell class="body-1" *cdkCellDef="let row">
<md-checkbox></md-checkbox>
</md-cell>
</ng-container>
</div>
<!-- Type Column -->
<ng-container cdkColumnDef="type">
<md-header-cell class="body-2" *cdkHeaderCellDef> Type </md-header-cell>
<md-cell class="body-1" *cdkCellDef="let row">
<md-chip-list><md-chip selected="true" color="blue">{{row.type}}</md-chip></md-chip-list>
</md-cell>
</ng-container>
<!-- Article Column -->
<ng-container cdkColumnDef="articleId">
<md-header-cell class="body-2" *cdkHeaderCellDef> Art.nr </md-header-cell>
<md-cell class="body-1" *cdkCellDef="let row"> {{row.articleId}} </md-cell>
</ng-container>
<!-- Description Column -->
<ng-container cdkColumnDef="description">
<md-header-cell class="body-2" *cdkHeaderCellDef> Beskrivning </md-header-cell>
<md-cell class="body-1" *cdkCellDef="let row"> {{row.description}} </md-cell>
</ng-container>
<!-- Amount Column -->
<ng-container cdkColumnDef="amount">
<md-header-cell class="body-2" *cdkHeaderCellDef> kg/st </md-header-cell>
<md-cell class="body-1" *cdkCellDef="let row"> {{row.amount}} kg </md-cell>
</ng-container>
<md-header-row *cdkHeaderRowDef="displayedColumns"></md-header-row>
<md-row *cdkRowDef="let row; columns: displayedColumns;"></md-row>
</md-table>
<button (click)="test()" md-button>Testing</button>
</div>
- 強大的文本
從你問題不是很清楚你想達到什麼目的,主要是你爲什麼不把多個複選框放在你需要的地方,什麼阻止你這樣做? – Vega
因爲複選框是爲創建的每個表格行創建的,這取決於每種情況下有多少行。複選框的數量永遠不會相同! – emilogge
所以你的問題是如何做到這一點? – Vega