开发者

knockout.js and asp.net dictionary

I am trying to access the key of a dictionary that was converted to json below. The value1 is the value of the dictinonary, but how do I get the key? The JSON shows an object of Details, with properties that are the keys if that makes sense. So how to I render the key 开发者_Go百科name from that property in a jquery template?

{{each(index, value) $data}}
        <div class="flaw">
        <div class="Title" data-bind="click: app.viewModel.caseStudy.showFlawDetails(index)"> ${value.Title} </div>
        <div class="Items">
        {{each(index1, value1) value.Details}}
             <div>${value.Details[index1]}: <input type="text" data-bind="value: value1" /></div>
        {{/each}}
        </div>
        </div>
        {{/each}}


I went with an object array. object[]

             public object[] Details { get; set; }

     Details = (from e in f.Elements()
                                                                        select new
                                                                        {
                                                                            Key = e.Name.ToString(),
                                                                            Value = GetValue(e)
                                                                        }).ToArray(),

        <script id="flawTemplate" type="text/html">
            {{each(index, value) $data}}
            <div class="flaw">
            <div class="Title" data-bind="click: app.viewModel.caseStudy.showFlawDetails(index)"> ${value.Title} </div>
            <div class="Items">
            {{each(index1, value1) value.Details}}
                 <div>${value1.Key}: <input type="text" data-bind="value: value1.Value" /></div>
        {{/each}}
        </div>
        </div>
        {{/each}}
    </script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜