gpt4 book ai didi

ajax - Kendo UI : Can't add a node to treeview when using custom schema

转载 作者:行者123 更新时间:2023-12-03 22:51:03 25 4
gpt4 key购买 nike

我有一个使用以下数据源初始化的 Kendo Tree :

var dataSource = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: '/Quota/Home/GetTemplateHierarchy',
dataType: 'json',
data: { hierarchyID: hierarchyID, quotaSetID: quotaSetID, batchSize: 10 }
}
},
schema: {
model: {
id: 'id',
hasChildren: 'hasChildren',
children: 'items',
fields: {
text: 'text'
}
}
}
});

有谁知道如何为这个数据源添加和创建一个新节点?我试过通用的 treeview.append({ text: "Boo"}) 但它没有做任何事情。我已成功删除节点,但似乎无法添加任何节点。文档不清楚如何在使用自定义模式时添加任何内容。

最佳答案

保罗,我想提出另一个解决方案......





    <!-- Kendo UI Web styles-->
<link href="../styles/kendo.common.min.css" rel="stylesheet" type="text/css"/>
<link href="../styles/kendo.default.min.css" rel="stylesheet" type="text/css"/>

<!-- Kendo UI Web scripts-->
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script src="../js/kendo.web.min.js" type="text/javascript"></script>

<!-- Local Styles -->
<style type="text/css">
</style>

<!-- Initialize Form Elements -->
<script type="text/javascript">
$(document).ready(function () {
function loadMore() {
var uid = $(this).data("uid");
var node = tree.findByUid(uid);
tree.insertBefore(content, node);
tree.remove(node);
addLoadMore(".k-i-pencil");
}

function addLoadMore(clss) {
$(clss, tree.element).closest(".k-item").on("click", loadMore);
}

var content = [
{
text :"node1",
items:[
{ text:"node1.1" },
{ text:"node1.2" },
{ text:"node1.3", spriteCssClass:"k-icon k-i-pencil" },
{ text:"node1.4" }
]
}
];

var tree = $("#tree").kendoTreeView({
dataSource:content
}).data("kendoTreeView");
addLoadMore(".k-i-pencil");
});
</script>

</head>
<body>
<div id="tree"></div>
</body>
</html>

在这里,我创建了一个从 JSON 加载内容的树(它应该替换为您的 ajaxAntiForgery )。树中有一个节点有一个图标(k-i-pencil)。然后我调用一个函数 addLoadMore ,它用 k-i-pencil 拦截节点上的点击,并将新内容添加到这个节点 - 使用 insertBefore 在带有 k-i-pencil 的内容之前插入新内容,然后删除旧节点)。
我认为这个示例与您使用按钮所做的非常相似。
因此,查看 loadMore 函数以了解我如何检测与我单击的位置相对应的 node(我提取 uid 并使用 uid 找到具有该 tree.findByUid 的节点)。
最后,我删除原始节点(调用 tree.remove )并使用 k-i-pencil 再次设置新节点的拦截器。
希望这与您拥有的非常接近。

关于ajax - Kendo UI : Can't add a node to treeview when using custom schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13498734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com