gpt4 book ai didi

javascript - 为 Angular 中的字典生成的下拉菜单设置 ng-model

转载 作者:行者123 更新时间:2023-12-02 17:16:28 25 4
gpt4 key购买 nike

我有一个下拉列表,可以从字典(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.OwnerUserIdint 值,我尝试通过 ng-model 指令绑定(bind)并设置下拉列表的选定值。但是下拉列表未选中。在这种情况下我做错了什么?

更新:部分 View 模型数据

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"
}

最佳答案

您正在寻找的是:

data-ng-options="mymodel.Case.OwnerUsers 中的 (key , value) 的键"

fiddle :http://jsfiddle.net/g8Xtp/

关于javascript - 为 Angular 中的字典生成的下拉菜单设置 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24406849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com