对象(与子对象)作为数据源的jqGrid名单 [英] jqgrid List of objects (with sub objects) as datasource

查看:480
本文介绍了对象(与子对象)作为数据源的jqGrid名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我拿这个吧。

Can someone give me a hand with this please.

我有2个班,Foo和武

i have 2 classes, Foo and Moo

public class Foo
{
    public int Id { get; set; }
    public int price { get; set; }
    public String code { get; set; }
     public Moo moo { get; set; }

public Foo()
{
}
 }


 public class MOO
 {
     public int Id { get; set; }
     public String firstname { get; set; }
     public String surname { get; set; }

     public MOO()
     {
     }
 }

我现在有FOOS名单

I have a list of FOOs now

List<Foo> foolist

我可以为我的jqGrid的数据源。做列价格和code,但我不能使用子场

I can make it a datasource for my jqgrid. and do columns for price and code, but I cant use the sub fields

我希望能够做这样的事

<trirand:JQGridColumn DataField="moo.firstname" Searchable="true" /> 

什么想法?
谢谢!

any ideas? Thanks!

推荐答案

基本上,你可以改变你的回报清单。您创建一个新的对象。例如:InfoFoo。您在使用Foo和武班设置其属性。然后返回这个类,列表。

Basically, you can change your return list. You create a new object. Example: InfoFoo. you set its property while using Foo and Moo classes. Then return this class, List.

public class InfoFoo
{
  public int Id { get; set; }
  public int price { get; set; }
  public String code { get; set; }
  public int MooId { get; set; }
  public String MooFirstname { get; set; }
  public String MooSurname { get; set; }
}

设置InfoFoo属性,

for setting InfoFoo properties,

List<InfoFoo> ListInfoFoo=new List<InfoFoo>(); 
foreach(var foo in List<Foo>)
 {
   var infoFoo=new InfoFoo();
   infoFoo.Id=foo.Id;
   infoFoo.Price=foo.Price;
   infoFoo.code=foo.code;
   infoFoo.MooId=foo.Moo.Id;
   infoFoo.MooFirstName=foo.Moo.firstName;
   infoFoo.MooSurname=foo.Moo.surname;  
   ListInfoFoo.Add(infoFoo);
  }

 return ListInfoFoo;

这篇关于对象(与子对象)作为数据源的jqGrid名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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