在“myItemA”对象的“排序”属性中,我想允许定义多个灵活命名的属性,例如“viewOrder”、“execOrder”、“persistOrder”......并像这样使用:
myItemA.sorting.viewOrder = 3;
myItemA.sorting.execOrder = 7;
etc.
我正在尝试ItemA的定义和属性排序,如下所示:
export abstract class ItemA {
constructor(
public id: string,
public name: string,
// (this is may not be correct - how to correct it ?)
public sorting?: [ {[name: string]: number} ],
...
然后像这样创建对象:
export const myItemA: ItemA =
{
id: 'A1',
name: 'A1',
// (compiler complains here - how to correct it ?)
sorting: [ {'viewOrder': 0}, {'execOrder': 0}, {etc.} ],
...
}