难度由JSON返回值显示 [英] Difficulty in displaying value returned by JSon

查看:174
本文介绍了难度由JSON返回值显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送一个列表,通过JSON的我的看法。

MyCalendar类

 公共MyCalendar()
{
  公众的DateTime日期{搞定;组;}
  公共字符串费用{搞定;组;}
  公众诠释天{获取;设置;}
}公开名单< MyCalendar> GetUserInfo()
{
    返回myCalendar.ToList();
}[授权]
公众的ActionResult GetMyCalendar()
{
    返回新JsonResult
    {
        数据=新MyCalendar()。GetUserInfo()
        JsonRequestBehavior = JsonRequestBehavior.AllowGet
    };
}

不过,我有困难在我的网格显示它们。发送为JSON的值如下:


我要显示它们如下:

我可以在JavaScript中的code哪能dothe以上吧。

 <脚本ID =DataTemplate中类型=文/ X-的jQuery-TMPL>
&所述; TR>
    < TD> $ {FormatJSONDate(日,YYYY / MM / DD)}< / TD>
    < TD> $ {}费用与LT; / TD>
    < TD> $ {天}< / TD>
< / TR>
< / SCRIPT>


解决方案

您可以改变你的数据是通过分组日期中返回JSON在服务器端的方式。然后,您可以得到的数据显示像上面一样。

的另一种选择是基于由日期,然后循环通过它并显示在一个表中的客户端的数据。

<一个href=\"http://stackoverflow.com/questions/1049789/create-nested-objects-in-javascript-like-groupby-in-c/6639981#6639981\">create在JavaScript中嵌套对象就像在C# GROUPBY

JQuery的ForEach循环?

I am sending a list to my view through Json.

MyCalendar Class

public MyCalendar()
{
  public DateTime Date {get; set;}
  public string Expense{ get; set;}
  public int Days{get;set;}
}

public List<MyCalendar> GetUserInfo()
{
    return myCalendar.ToList();
}

[Authorize]
public ActionResult GetMyCalendar()
{
    return new JsonResult
    {
        Data = new MyCalendar().GetUserInfo(),
        JsonRequestBehavior = JsonRequestBehavior.AllowGet
    };
}

However, I am having difficulty to display them in my grid. The values sent as json are as follows:


I want to display them as follows:

Can I have the code in javascript how I can dothe above please.

<script id="dataTemplate" type="text/x-jquery-tmpl">
<tr>
    <td>${FormatJSONDate(Date, "yyyy/MM/dd")}</td>
    <td>${Expense}</td>
    <td>${Days}</td>
</tr>
</script>

解决方案

You could change the way your data is returned in JSON on the server side by grouping by date. You could then get the data to display like it does above.

The other option is to group your data on the client side by date and then loop through it and display in a table.

create nested objects in javascript like groupby in C#

JQuery ForEach loop?

这篇关于难度由JSON返回值显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆