0
export abstract class GridColumn {
public field?: string;
public sortField?: string;
public header?: string;
public footer?: string;
public sortable?: any = true;
public editable?: boolean = false;
public filter?: boolean = true;
public filterMatchMode?: string = 'contains';
public filterPlaceholder?: string;
public style?: any;
public styleClass?: string;
public hidden?: boolean = false;
public selectionMode?: string = 'multiple';
public frozen?: boolean;
}
例如,这样做只会返回一个具有这些定义属性的对象。Angular2 init抽象类与对象文字
private gridConf: GridColumn = <GridColumn>{
field: "test2",
header: "Test2",
filter: true,
filterMatchMode: "contains",
filterPlaceholder: "Search from Test",
sortable: true,
selectionMode: "single"
};
我要的是GridColumn
具有所有定义的属性和所有默认值类型的对象。
这不起作用:
private gridConf: GridColumn = GridColumn({
field: "test2",
header: "Test2",
filter: true,
filterMatchMode: "contains",
filterPlaceholder: "Search from Test",
sortable: true,
selectionMode: "single"
});
构造会强迫我写一个漫长的,我会一直都在一个特定的顺序添加的所有属性。
的最终目标是使用这样的事情有任何顺序所有默认和/或定义的属性:
private columns: Array<GridColumn> = [
<GridColumn>{
field: "test",
selectionMode: "single",
filter: true,
filterMatchMode: "contains",
filterPlaceholder: "Search from Test",
sortable: true,
header: "Test"
},
<GridColumn>{
field: "test2",
header: "Test2",
filter: true,
filterMatchMode: "contains",
filterPlaceholder: "Search from Test",
sortable: true,
selectionMode: "single"
}
];
最近的“黑客”我能找到的是去除抽象和添加,其中场指的是它本身:
public constructor(
fields?: GridColumn) {
if (fields) Object.assign(this, fields);
}