垂直网格/表的布局的Javascript
问题描述:
我需要显示一些JSON数据垂直而非水平:垂直网格/表的布局的Javascript
column1的:VALUE1
列2:值2
等。
这些值来自数据库,我需要能够滚动从数据库返回的记录。
这是一个使用C#的MVC3应用程序,我愿意接受任何可能的解决方案。
UPDATE:
虽然低于不正是我需要的,它让我在正确的道路上使用,我还没有想过以前透视表。
答
如果你想使用LINQ,你转换是这样的:
var pivotTable = from m in db.table
select new
{
Column1 = (from t1 in m
where t1.Field == "column1"
select t1.Value,
Column2 = (from t2 in m
where t2.Field == "column2"
select t2.Value
};
Json(pivotTable, JsonRequestBehavior.AllowGet)
先来看看:
-----------------
Field | Value |
-----------------
column1 | 14 |
column2 | 34 |
column1 | 14 |
column2 | 36 |
column1 | 18 |
column2 | 34 |
LINQ查询后
Column1 | Column2 |
-------------------
14 | 34 |
14 | 36 |
18 | 34 |
不幸的是我不能使用LINQ,使用mysql后端和linq需要很长时间才能返回我需要的数据。尽管你可能会让我走向正确的方向 – user2043530