本着 Ryan Cavanaugh 接受的答案的精神,我不允许链接到该答案,它提出了以下结构:
var map: { [email: string]: Customer; } = { };
为了模拟一个Customer
带有字符串键的字典,该字符串键是一个电子邮件地址,我试图实现一个类似的伪字典SelectionOtherInputDescriptor
1:
export class SelectionOtherInputDescriptor {
constructor(public selectionName: string, public otherKey: any, public otherInputElementId: string) { }
}
export class SelectionOtherInputHelper {
selectionsWithOther: { [selectionKey: string]: SelectionOtherInputDescriptor; } = {};
getAllSelectionOthers() {
var things = $("[" + ATT_SELECTION_OTHER_FOR + "]");
for (var i = 0; i < things.length; i++) {
var selectionName = $(things[i]).attr(ATT_SELECTION_OTHER_FOR);
var desc = new SelectionOtherInputDescriptor(selectionName, 0, $(things[i]).attr("id"));
this.selectionsWithOther[selectionName] = desc;
};
for (var i in this.selectionsWithOther) {
window.console.log(i);
}
};
}
但是,我的变量selectionsWithOther
似乎总是只包含三个字符串(在具有三个选择和其他元素的测试页面中),即selectionKey
值。
1描述当用户在选择元素上选择“其他”时捕获实际值的输入。