0

なぜこれを正しく理解できないのか疑問に思っていました。「ジョブ」オブジェクトのコレクションを返す MVC に JSONResult があります。「Job」オブジェクトのプロパティの 1 つに Dictionary があります。これを「Job」エンティティ テンプレートに追加する方法がわからないので、内部テンプレートのすべての値を表示できます。現在のオブジェクト設計はジョブであり、各ジョブにはジョブ フェーズのディクショナリがあります。次のコードは、私が現在使用しているものです。

Job.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>
4

1 に答える 1

1

クライアント側の JSONCodesが文字列値を持つプレーンな JavaScript オブジェクトに対応する場合は{{props}}、プロパティを反復処理するために使用できます。次に例を示します。

<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
    {{props Codes}}
        <li role="presentation" class="dropdown-header">Key: {{>key}} Value: {{>prop}}</li>
    {{/props}}
</ul> 

http://www.jsviews.com/#propstagを参照してください

于 2015-03-11T02:00:58.210 に答える