【问题标题】:ASP.NET MVC Kendo UI Treemap - Data?ASP.NET MVC Kendo UI Treemap - 数据?
【发布时间】:2017-07-12 12:55:11
【问题描述】:

有人知道如何在 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;" })
)

在哪里可以设置值?

提前致谢

【问题讨论】:

    标签: c# asp.net-mvc kendo-ui telerik


    【解决方案1】:

    这是个好问题。该演示没有显示用于填充数据的控制器方法。我敢打赌它使用的是HierarchicalDataSource,它支持任何具有自引用集合属性的自定义名称/值类。我认为您需要下载演示以查看演示中的控制器在做什么,但是,我会为您尽力而为。一旦您知道签名,服务器绑定实际上非常简单。在这里,我假设 Items 属性是父子之间的递归关系。在这种情况下,国家 - 州 - 城市。

    有一个使用 HierarchicalDataSource here 的 jQuery 示例,但是,您不需要使用该方法。

    如果您的数据不是分层的,您可以只发送一个简单的名称/值对列表并删除 TreeMap ui 配置中的 Model 属性。

    模型:

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

    【讨论】:

    • 这就是我需要的——非常感谢!!
    猜你喜欢
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多