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

How to apply classes to parent and child nodes of 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");
          }));
      })
)

但是,它没有应用 类。

请让我知道哪里做错了。

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

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

)