jqgrid List of objects (with sub objects) as datasource

我只是一个虾纸丫 提交于 2019-12-08 04:28:06

问题


Can someone give me a hand with this please.

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()
     {
     }
 }

I have a list of FOOs now

List<Foo> foolist

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

I would love to be able to do something like this

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

any ideas? Thanks!


回答1:


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; }
}

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;


来源:https://stackoverflow.com/questions/9682382/jqgrid-list-of-objects-with-sub-objects-as-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!