Easy UI 关联表的字段展示

刚接触的easy UI ,发现展示关联表的字段的时候,卡住了 好一段时间,后来通过qq群询问,终于得到答案

 

实体Record 

 public class Record:Base
    {
        public Guid UserId { get; set; }
        public Guid CarId { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        public decimal TotalPrice { get; set; }

        /// <summary>
        /// 公里数
        /// </summary>
        public decimal Kilometre { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal UnitPrice { get; set; }

        public virtual Car Car { get; set; }
        public virtual User User { get; set; }
    }
View Code

 

实体Car

 public class Car : Base
    {
        /// <summary>
        /// 车牌
        /// </summary>
        [StringLength(20)]
        public string Number { get; set; }

        /// <summary>
        /// 颜色
        /// </summary>
        [StringLength(5)]
        public string Color { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [StringLength(10)]
        public string Name { get; set; }

        /// <summary>
        /// 用户id
        /// </summary>
        public Guid UserId { get; set; }
    }
View Code

 

在ui层 显示 car 的字段 Nuber 如下

     $('#dg').datagrid({
                url: 'record/page',
                pagination: true,
                rownumbers: true,
                singleSelect: true,
                //checkOnSelect: false, selectOnCheck: false,
                columns:
             [[
                 { field: "Id", title: "Id", hidden: true },
                 //{ field: "ck", checkbox:true },

                 { field: "RefuelTime", title: "加油日期" },

                 {
                     field: 'Car', title: "车牌", formatter: function (value) {
                         return value.Number
                     }
                 },
                 {
                     field: "Phone", title: "电话", formatter: function (value, row, index) {
                         return row.User.Phone;
                     }
                 },
                 
                 { field: "TotalPrice", title: "加油总价" },
                  { field: "UnitPrice", title: "每升价格" },
                  { field: "Kilometre", title: "行驶里程" }
             ]]
            });
        });
View Code

 

posted @ 2015-03-26 15:06  Tauren  阅读(325)  评论(0编辑  收藏  举报