我有从Dictionary(int,string)中检索数据的下拉列表:
<select
class="form-control"
data-ng-model="model.Case.OwnerUserId"
data-ng-options="key as value for (key,value) in model.OwnerUsers" >
</select>
model.Case.OwnerUserId
是int
值,我尝试通过ng-model
指令绑定并为dropdown设置选定的值。但是未选中下拉列表。我在这种情况下做错了什么?
更新:部分视图模型数据
public class CaseViewModel
{
public Case Case { get; set; }
public Dictionary<int,string> Facilities { get; set; }
public Dictionary<int, string> OwnerUsers { get; set; }
}
public class Case
{
public int CaseId { get; set; }
public int ResidentId { get; set; }
public int OwnerUserId { get; set; } ...
序列化后的JS模型示例:
{
"Case": {
"CaseId": 27,
"ResidentId": 4478,
"OwnerUserId": 15,
"CreatedByUserId": 20,
"LastUpdatedUserId": null,
"ReceivedDate": "2014-06-23T12:49:54.713", ...
"OwnerUsers": {
"35": "a.markov",
"15": "a.zaharov",
"20": "e.martynov",
"36": "a.oryel",
"40": "test01"
}
答案 0 :(得分:2)
您正在寻找的是:
data-ng-options="key for (key , value) in mymodel.Case.OwnerUsers"
答案 1 :(得分:0)
如果要包含值和描述
,请尝试以下操作key as value for (key , value) in CONTROLLER.DICTIONARY