如何将类应用于剑道树视图的父节点和子节点

时间:2016-02-17 14:32:29

标签: jquery kendo-ui kendo-asp.net-mvc telerik-mvc kendo-treeview

如何将CSS类添加到Kendo树视图的父节点和子节点?

我试过了:

@(Html.Kendo().TreeView()
      .Name("Countries")
      .DataTextField("CityName")
      .Checkboxes(checkboxes => checkboxes
          .Name("cityCheck")
          .CheckChildren(true)
      )
      .BindTo((IEnumerable<CountryModel>)ViewBag.Country, (Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
      {
          mappings.For<CityModel>(binding => binding.ItemDataBound((item, parent) =>
          {
              item.Id = parent.Id.ToString();
              item.Text = parent.Name;
              item.HtmlAttributes.Add("class", "citycheck");
          })
          .Children(p => p.City));
          mappings.For<CityModel>(binding => binding.ItemDataBound((item, child) =>
          {
               item.Id = child.Code;
               item.Text = child.Name;
               item.HtmlAttributes.Add("class", "citycheck");
          }));
      })
)

但是,它没有应用这些类。

请告诉我在哪里犯了错误。

1 个答案:

答案 0 :(得分:1)

我在我的问题中发布的代码现在工作正常。

  @(Html.Kendo().TreeView()
  .Name("Countries")
  .DataTextField("CityName")
  .Checkboxes(checkboxes => checkboxes
      .Name("cityCheck")
      .CheckChildren(true)
  )
  .BindTo((IEnumerable<CountryModel>)ViewBag.Country, (Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
  {
      mappings.For<CityModel>(binding => binding.ItemDataBound((item, parent) =>
      {
          item.Id = parent.Id.ToString();
          item.Text = parent.Name;
          item.HtmlAttributes.Add("class", "citycheck");
      })
      .Children(p => p.City));
      mappings.For<CityModel>(binding => binding.ItemDataBound((item, child) =>
      {
           item.Id = child.Code;
           item.Text = child.Name;
           item.HtmlAttributes.Add("class", "citycheck");
      }));
  })