从下拉菜单中选择Kendo Treeview的值

时间:2019-09-17 07:56:14

标签: kendo-ui kendo-grid kendo-treeview kendo-dropdown

在这里,我有一个剑道下拉菜单和树状视图。如果我从下拉列表中选择值,我想要达到的目标将被选中(在树状视图中)(如下图所示)。感谢您的帮助。

  $("#dropdownlist").kendoDropDownList({
    dataSource: [{ id:1, ledger: "Asset" }, 
      { id:2, ledger: "Current Asset" },
      { id:3, ledger: "Income" },
      { id:4, ledger: "Equity" },
      { id:5, ledger: "Sales" }], 
    dataTextField: "ledger",
    dataValueField: "id",
    select: onSelect
  });


  $("#treeview").kendoTreeView({
    dataSource: [{ id:1, ledger: "Asset" }, 
      { id:2, ledger: "Current Asset" },
      { id:3, ledger: "Income" },
      { id:4, ledger: "Equity" },
      { id:5, ledger: "Sales" }],
    dataTextField: "ledger",
    dataValueField: "id"
  });


  function onSelect(e) {
    if (e.dataItem) {
      var dataItem = e.dataItem;
      console.log("select (" + dataItem.ledger + " : " + dataItem.id + ")");
    } 
  };

DEMO IN DOJO

enter image description here

1 个答案:

答案 0 :(得分:1)

您在这里:https://docs.telerik.com/kendo-ui/api/javascript/ui/treeview/methods/select

function onSelect(e) {
if (e.dataItem) {
  var dataItem = e.dataItem;
  var treeview = $("#treeview").data("kendoTreeView");
  var bar = treeview.findByText(dataItem.ledger);
        treeview.select(bar);    
  console.log("select (" + dataItem.ledger + " : " + dataItem.id + ")");
}