1

如何將CSS類添加到Kendo樹視圖的父節點和子節點?如何將類應用於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

我在我的問題中發佈的代碼現在工作正常。

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

相關問題