0

我有一个 json 这是这样的:

        var jsonData = new
        {
            total = totalPages,
            page = page,
            records = totalRecords,
            rows = reservations.Select(x => new { x.ReservationId, x.Employee.Name,roomName = x.Room.Name, x.Date, x.StartTime, x.EndTime, x.Notes}).ToList()
                .Select(x => new
                {
                    id = x.ReservationId,
                    cell = new string[]
                    {
                    roomName,
                    x.Name,
                    x.Date.ToString().Split(' ')[0],
                    x.StartTime.ToString().Remove(5) +" - " +x.EndTime.ToString().Remove(5),
                    x.Notes,
                    String.Format("<input type=\"button\" value=\"DETAILS\" onclick=\"window.location.href='/Reservation/Details/{0}'\"/>&nbsp &nbsp<input type=\"button\" value=\"EDIT\" onclick=\"window.location.href='/Reservation/Edit/{0}'\"/>&nbsp &nbsp<input type=\"button\" value=\"DELETE\" onclick=\"window.location.href='/Reservation/Delete/{0}'\"/>", x.ReservationId), 
                    }
                }).ToArray(),
        };

此 json 将返回到 jqGrid。当我在第一个 select 语句中键入 x.Room.Name 时,发生错误,因为已经存在同名的属性(iexEmployee.Name)。

所以我尝试了“roomName = x.Room.Name”并将roomName放在单元格内容中。

但是,当 json 返回到我的 jqGrid 时,应该包含 roomName 的列是空的。我如何以其他方式显示 x.Room.Name 的值?

4

1 回答 1

1

由于您已重命名该列以roomName确保在客户端上有相应的列:

$('#grid').jqGrid({
    colNames: [ 'roomName', 'Name', ..... other columns ],
    colModel: [
        { name: 'roomName', index: 'roomName' },
        { name: 'Name', index: 'Name' },
        .....
    ],
    ........
});
于 2012-05-24T06:38:53.290 回答