1

我的树视图代码是这样的:

@(Html.Kendo().TreeView()
   .Name("treeview")
   .DragAndDrop(true)
   .HtmlAttributes(new{@class="demo-section"})
   .DataTextField("Name")
   .DataSource(dataSource=>datasource.Read(read=>read.Action("Employees","Remote_Data")))

)

我想要的是:当我将一个节点作为子节点拖放到另一个节点时,我只想复制第一个节点而不是删除它。

4

1 回答 1

1

我是这样做的:

@(Html.Kendo().TreeView()
   .Name("treeview")
   .DragAndDrop(true)
   .Events(events=>events.Drop("onDrop"))
   .HtmlAttributes(new{@class="demo-section"})
   .DataTextField("Name")
   .DataSource(dataSource=>datasource.Read(read=>read.Action("Employees","Remote_Data"))))

脚本代码:

function onDrop(e){
      var treeview=$("#treeview").data("kendoTreeView");
      var destination=$(e.destinationNode);
      var treeItem={
          Name:treeview.text(e.sourceNode),
          tagId:e.sourceNode.tagId
      };
                if (e.valid && destination.length > 0) {
                    if (e.dropPosition == "over") {
                        rightTree.append(treeItem, destination);
                        rightTree.expand(e.destinationNode);
                    }
                    else if (e.dropPosition == "before") {
                        rightTree.insertBefore(treeItem, destination);
                    }
                    else if (e.dropPosition == "after") {
                        rightTree.insertAfter(treeItem, destination);
                    }
                }
                else {
                    rightTree.append(treeItem, null);
                    $('#NoItemsMessage').hide();
                }
                e.setValid(false);
}
于 2013-05-31T04:53:23.970 回答