我想知道为什么似乎无法正确记录下来。我在 MVC 中有一个 JSONResult 返回“作业”对象的集合。“作业”对象的属性之一是字典。我似乎无法弄清楚如何将其添加到“作业”实体模板中,以便我可以显示内部模板的所有值。当前的对象设计将是一个作业,每个作业都有一个作业阶段字典。以下代码是我目前使用的:
作业.cs
public string Id { get; set; }
public string Name { get; set; }
public string CustomerName { get; set; }
public string Phase {get;set;}
public string PhaseText { get; set; }
public Dictionary<String,String> Codes { get; set; }
客户端脚本:
<script id="jobLevelTmpl" type="text/x-jsrender">
<tr class="row-header">
<td class="col-lg-1">{{:Id}}</td>
<td class="col-lg-4">{{:Name}}</td>
<td class="col-lg-1" title="Status code: '{{:Phase}}'">{{:PhaseText}}</td>
<td class="col-lg-1"><a jobid="{{:Id}}">View Job Details</a></td>
<td class="col-lg-1">
<div class="dropdown">
<button class="btn btn-warning dropdown-toggle" type="button" id="menu1" data-toggle="dropdown">
Phase
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
{{for Codes}}
<!-- This is where I do not know what to call or how to call the key or value of the dictionary items -->
<li role="presentation" class="dropdown-header">{{>code}}</li>
{{/for}}
</ul>
</div>
</td>
<td class="col-lg-1"><a href="javascript:function(){return false;}" jobid="{{:Id}}" class="btn btn-info expand-job">Update</a></td>
</tr>
<tr>
<td class="col-lg-12 details-info" style="display:none;">
<a href='#' onclick='parent.$.colorbox.close(); return false;' style="float:right;">Close</a>
</td>
</tr>
</script>