【问题标题】:Kendo MVC TreeList not Rendering from Initial BindToKendo MVC TreeList 未从初始 BindTo 渲染
【发布时间】:2018-11-29 16:57:29
【问题描述】:

我的MVC ViewModel 包含要在我的Kendo TreeList 中显示的初始记录列表。但是,TreeList 没有呈现初始列表……我不明白为什么。

要求:

  • 如果存在初始记录...显示它们
  • 无法在初始渲染上执行读取操作(其他控件稍后会管理)

对于其他剑道控件,您可以设置:

  • 自动绑定(假)
  • BindTo(Model.MyCollectiom)

...并且 READ ACTION 不执行。但是目前 TreeList 失败了。

我的剃须刀看起来像:
在初始渲染记录确实存在(见下图)

@(Html.Kendo().TreeList<DeviceHierarchyDataItem>()
              .Name("treeTarget")
              .Columns(columns =>
              {
                  columns.Add().Field(e => e.DisplayName)
                               .TemplateId("tmplDisplayName")
                               .Title(" ");
              })
              .BindTo(Model.TargetDevices)
              .AutoBind(false)
              .DataSource(dataSource => dataSource
                         .Read(read => read.Action("find", "devicehierarchy", new { Area = "" })
                                           .Data("window.etp.pageController.getFilter"))
                         .ServerOperation(false)
                         .Model(m =>
                         {
                             m.Id(f => f.Id);
                             m.ParentId(f => f.ChildOf);
                             m.Expanded(true);
                             m.Field(f => f.DisplayName);
                         }))
              .Sortable())

【问题讨论】:

  • 在纯 JS 中,我们通过引用像 dataSource: { data: myData } 这样的数据对象来做到这一点,但不确定 BindTo() 是否在幕后这样做。我建议您检查 asp.net mvc dataSource 中是否存在.Data() 方法(我查看了文档,但找不到 asp.net dataSource 的好文档)。

标签: asp.net-mvc kendo-ui kendo-treelist


【解决方案1】:

奇怪的是,TreeList MVC 控件不支持绑定到本地数据... 至少不在july 2018...

建议改用jquery control

然后将Model中的数据转换成json字符串:

$(document).ready(function () {
                var dataSource = new kendo.data.TreeListDataSource({
                    data: @Html.Raw(Json.Encode(@Model.TargetDevices)),
                    schema: {
                        model: {
                        id: "Id", 
                        parentid: "ChildOf", 
                        expanded: true
                        }
                    }
                });

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多