ASP.NET MVC Kendo UI 树图 - 数据?
ASP.NET MVC Kendo UI Treemap - Data?
有谁知道如何在 ASP.NET MVC 中为 Kendo Treemap 设置数据?
我有一个这样的列表(C# 列表):
Item | Count
------------------
Item 1 | 4
Item 2 | 7
Item 3 | 2
Item 4 | 9
这是演示站点 (http://demos.telerik.com/aspnet-mvc/treemap) 中的 cshtml 部分:
@(Html.Kendo().TreeMap()
.Name("treeMap")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("_PopulationUSA", "TreeMap")
)
.Model(m => m.Children("Items"))
)
.ValueField("Value")
.TextField("Name")
.HtmlAttributes(new { style = "height:600px; font-size: 12px;" })
)
在哪里设置值?
提前致谢
这是个好问题。该演示没有显示用于填充数据的控制器方法。我打赌它正在使用 HierarchicalDataSource
,它支持任何自定义 Name/Value class 和自引用集合 属性。我认为您需要下载演示以查看演示中的控制器在做什么,但是,我会尽力为您提供帮助。一旦您知道签名,服务器绑定实际上非常简单。在这里,我假设 Items 属性 是父子之间的递归关系。在这种情况下,国家 - 州 - 城市。
有一个使用 HierarchicalDataSource
here 的 jQuery 示例,但是,您不需要使用该方法。
如果您的数据不是分层的,您可以只发送一个简单的 name/value 对列表并删除 TreeMap ui 配置中的模型 属性。
模特:
public class MyModel
{
public string Name{ get; set; }
public int Value{ get; set; }
List<MyModel> Items{get;set;}
}
控制器方法:
public class MyController : Controller
{
[OutputCache(NoStore = true, Duration = 0)]
public ActionResult GetMyTreeMapData(int someID, [DataSourceRequest] DataSourceRequest request)
{
List<MyModel> items = new List<MyModel>();
items=SomeMethodToRecursivelyFillYourParentAndChildren();
return Json(items.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
}
UI绑定:
@(Html.Kendo().TreeMap()
.Name("treeMap")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetMyTreeMapData", "MyController")
)
.Model(m => m.Children("Items"))
)
.ValueField("Value")
.TextField("Name")
.HtmlAttributes(new { style = "height:600px; font-size: 12px;" })
)
有谁知道如何在 ASP.NET MVC 中为 Kendo Treemap 设置数据? 我有一个这样的列表(C# 列表):
Item | Count
------------------
Item 1 | 4
Item 2 | 7
Item 3 | 2
Item 4 | 9
这是演示站点 (http://demos.telerik.com/aspnet-mvc/treemap) 中的 cshtml 部分:
@(Html.Kendo().TreeMap()
.Name("treeMap")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("_PopulationUSA", "TreeMap")
)
.Model(m => m.Children("Items"))
)
.ValueField("Value")
.TextField("Name")
.HtmlAttributes(new { style = "height:600px; font-size: 12px;" })
)
在哪里设置值?
提前致谢
这是个好问题。该演示没有显示用于填充数据的控制器方法。我打赌它正在使用 HierarchicalDataSource
,它支持任何自定义 Name/Value class 和自引用集合 属性。我认为您需要下载演示以查看演示中的控制器在做什么,但是,我会尽力为您提供帮助。一旦您知道签名,服务器绑定实际上非常简单。在这里,我假设 Items 属性 是父子之间的递归关系。在这种情况下,国家 - 州 - 城市。
有一个使用 HierarchicalDataSource
here 的 jQuery 示例,但是,您不需要使用该方法。
如果您的数据不是分层的,您可以只发送一个简单的 name/value 对列表并删除 TreeMap ui 配置中的模型 属性。
模特:
public class MyModel
{
public string Name{ get; set; }
public int Value{ get; set; }
List<MyModel> Items{get;set;}
}
控制器方法:
public class MyController : Controller
{
[OutputCache(NoStore = true, Duration = 0)]
public ActionResult GetMyTreeMapData(int someID, [DataSourceRequest] DataSourceRequest request)
{
List<MyModel> items = new List<MyModel>();
items=SomeMethodToRecursivelyFillYourParentAndChildren();
return Json(items.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
}
UI绑定:
@(Html.Kendo().TreeMap()
.Name("treeMap")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetMyTreeMapData", "MyController")
)
.Model(m => m.Children("Items"))
)
.ValueField("Value")
.TextField("Name")
.HtmlAttributes(new { style = "height:600px; font-size: 12px;" })
)