我正在尝试在树面板中执行拖放事件,但有一些限制。我有两个树视图,我需要将右树的内容拖到左树,但有一些限制。1)我需要检查拖动的项目是否在左树上。如果是,则不允许任务完成 2)如果拖动的项目有子节点,则应显示有关具有子节点的节点的通知。如果用户单击是,它应该允许复制所有节点,如果不是,它应该只允许父节点
我在javascript中编写了如下代码(注意我使用剃刀作为用户界面)
function (node, data, overModel, dropPosition, dropFunction) {
var record = data.records[0].data;
var nodeElem = data.item;
//before dropping item to the destination tree view we have to check if the item already exists
var exists = (nodeElem.find('.completed').length > 0);
if(exists)
{
return false;
}
//validate hierarchy level and parent node
var target = overModel;
//target.parentNode.data.id
var depth=target.getDepth();
if ( depth > 1) {
if (target.data.id != record.parentId) {
return false;
}
}
//check for existing nodes
var destTree = Ext.getCmp('tpDestination');
var found = findChildNodes(record.id, destTree);//dind childnodes checks the presence of chiild node
if (found) {
Ext.Msg.alert({
title: 'Alert',
msg: "The destination tree contains one of it's child domain. Please remove it's children and retry.",
buttons: Ext.MessageBox.OK
});
return false;
}
//allow copy of nodes. it overrides the move functionality
data.copy = true;
//show the confirmation message, if the node has children.
var isLeaf = record.leaf;
if (!isLeaf) {
//wait until confirmation complete
dropFunction.wait = true;
Ext.Msg.confirm({
title: 'Confirm',
msg: "Do you want to copy children also?",
buttons: Ext.MessageBox.YESNO,
fn: function (btn) {
if (btn == 'no') {
data.copyChildren = false;
}
dropFunction.processDrop();
}
});
}
data.dropNode = data.records[0];
return true; };
完成是右侧面板的节点类,代码应该检查拖动的元素是否存在已完成的类,但它不工作,当用户单击“否”时我不知道它仍然沿子节点添加所有节点