我在将enum与select from html连接时遇到问题。我的枚举结构如下所示:
enum Color {
Green,
Red,
Blue
}
我想以某种方式使用角度将这个枚举绑定到html select标记。有什么想法吗?
谢谢
英国
最佳答案
当您的枚举编译为javascript时,它将成为以下对象。你可以在打字机操场上看到等价的JavaScript here。
{
0: "Green"
1: "Red"
2: "Blue"
"Blue": 2
"Green": 0
"Red": 1
}
现在,如您所见,如果您将它与
<select>
绑定,您将得到数值和非数值项。假设您只希望非数字项显示在列表中,则需要对其进行筛选。