这里有两个Kendo树视图,这里的First One(名为-#credentialsTreeView")包含带有父节点的复选框的节点,它的子节点和内部子节点等,
还有另一个剑道树视图(名为#CurriculumcustomCredTreeView),我想要做的是,我在第一个树视图中检查的所有节点都应该通过保持确切的父子关系添加到第二个树视图中,例如,如果存在像parent1==>child1==>child2
这样的层次结构(它是child1的子节点),如果检查了child2,那么它的父节点(包括child2)应该被添加到第二个树视图中,但问题是,第一个:可以添加父节点,因为它可以添加到用户i / f和数据源中的树视图中,因此它工作正常但是再次将它的子节点附加到这个添加的节点时它不会添加到数据源,所以在向它添加下一个子节点时,不可能从我需要添加下一个节点的数据源获取节点的细节,
剑道版 - 2013.3.1119.440
请查看我使用的代码。请尽快告诉我详细信息。
function onAddToRequirement()
{
var treeViewCraftData = $("#credentialsTreeView").data("kendoTreeView").dataSource.data();//1st tree view which contains initially loaded list of nodes with different levels(with multiple childs and innerchilds with check boxes)
var treeViewSelectedTextList = [];
var requirementTreeView = $("#CurriculumcustomCredTreeView").data("kendoTreeView");//2nd tree view to which the selected nodes from 1st tree view to be added dynamically
$("#credentialsTreeView input[type=checkbox]:checked").closest(".k-item").each(function () {
treeViewSelectedTextList.push(
$(this).closest('.k-item').text()
);
});
var treeViewSelectedList = [];
var currentCraftNode = null;//currently three levels are there as craft==>its levels(can be multiple)==>it's Modules(can be multiple)
var currentLevelNode = null;
var currentModuleNode = null;
for (var j = 0; j < treeViewCraftData.length; j++) //treeViewCraftData contains the entire data in the datsource of 1st tree view and looping through it
{
if (treeViewCraftData[j].hasChildren)//checking craft has children
{
var treeViewLevelData = treeViewCraftData[j].children.data();//if so taking all its, levels (craft,s children)
currentCraftNode = treeViewCraftData[j];
for (var k = 0; k < treeViewLevelData.length; k++) //looping through levels
{
if (treeViewLevelData[k].hasChildren) //checking levels has children(named modules here)
{
currentLevelNode = treeViewLevelData[k];
var treeViewModuleData = treeViewLevelData[k].children.data();
for (var l = 0; l < treeViewModuleData.length; l++) //looping through modules(inner children) and checking if it is checked
{
if (treeViewModuleData[k].checked || $.inArray(treeViewModuleData[k].text, treeViewSelectedTextList) > -1)
{
currentModuleNode = treeViewModuleData[k];
if (requirementTreeView.dataSource._data.length > 0)//added condition to prevent it from adding duplicate nodes to 2nd tree view,in first case directly it goes to else part
{
var dataItemcraft1 = null;
var dataItemlevel1 = null;
$(requirementTreeView.dataSource.data()).each(function()
{
if (this.id !== currentCraftNode.id)
{
requirementTreeView.append({//appending 1st node
Name: currentCraftNode.Name,
id: currentCraftNode.id,
hasChildren:currentCraftNode.hasChildren,
//items: treeViewSelectedList.length != 0 ? treeViewSelectedList : null
}, null);
}
});
dataItemcraft1 = requirementTreeView.dataSource.get(currentCraftNode.id);
$(requirementTreeView.dataSource.data()).each(function() {
if (this.id !== currentLevelNode.id) {//appending 2nd node to first node
requirementTreeView.append({
Name: currentLevelNode.Name,
id: currentLevelNode.id,
hasChildren: currentLevelNode.hasChildren,
}, requirementTreeView.dataSource.get(dataItemcraft1.uid));
}
});
dataItemlevel1 = requirementTreeView.dataSource.get(currentCraftNode.id);//here it throws exception as above node is not added to the datsource
$(requirementTreeView.dataSource.data()).each(function() {//code to append 3rd node to above added node
//ebugger;
if (this.id !== currentModuleNode.id) {
requirementTreeView.append({
Name: currentModuleNode.Name,
id: currentModuleNode.id,
hasChildren: currentModuleNode.hasChildren,
//items: treeViewSelectedList.length != 0 ? treeViewSelectedList : null
}, requirementTreeView.dataSource.get(dataItemlevel1.uid));
}
});
dataItemcraft1 = null;
dataItemlevel1 = null;
} else
{
requirementTreeView.append//appending 1st node
({
Name: currentCraftNode.Name,
id: currentCraftNode.id,
hasChildren: currentCraftNode.hasChildren,
Value: currentCraftNode.id
});
var dataItemcraft = requirementTreeView.dataSource.get(currentCraftNode.id);//working fine
requirementTreeView.append//appending 2nd node to first node
({
Name: currentLevelNode.Name,
id: currentLevelNode.id,
hasChildren: currentLevelNode.hasChildren,
}, requirementTreeView.findByUid(dataItemcraft.uid));
requirementTreeView.expand(requirementTreeView.findByUid(dataItemcraft.uid));
var dataItemlevel = requirementTreeView.dataSource.get(currentLevelNode.id);//here it throws exception as above node is not added to the datsource
requirementTreeView.append({
Name: currentModuleNode.Name,
id: currentModuleNode.id,
hasChildren: currentModuleNode.hasChildren,
//items: treeViewSelectedList.length != 0 ? treeViewSelectedList : null
}, requirementTreeView.findByUid(dataItemlevel.uid));
requirementTreeView.expand(requirementTreeView.findByUid(dataItemlevel.uid));
dataItemcraft = null;
dataItemlevel = null;
}
}
}
} else {
}
}
}
}