dnd,如何限制删除到某些节点类型? [英] dnd, how to restrict dropping to certain node types?

查看:110
本文介绍了dnd,如何限制删除到某些节点类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有37种不同的节点类型. 我正在尝试实现拖放. 这可行,但是我需要严格限制可以拖动的类型以及可以将它们拖放到的位置. 不幸的是,我在文档(http://www.jstree.com/documentation)中找不到任何有用的信息.

I have 37 different node types. I am trying to implement drag and drop. This works but I need to restrict exactly which types can be dragged and where they can be dropped. I can't find any useful information in the docs unfortunately (http://www.jstree.com/documentation).

到目前为止,我已经尝试了三种方法:

So far I have tried three methods:

第一:根据节点类型,在drag_check回调中定义true或false的返回值:

first: defining return values of true or false in the drag_check callback depending on the node type:

$("#demo1").jstree({
    "dnd" : {
        "drag_check" : function () {

秒:绑定到prepare_move.jstree事件,并根据节点类型返回true或false值:

second: binding to the prepare_move.jstree event and returning true or false values depending on the node type:

.bind("prepare_move.jstree", function (e, data) {
   if (data.rslt.o.attr("typ") === "tpop") {

第三:使用类型插件并在那里定义有效的子代:

third: using the types plugin and defining valid children there:

$("#tree").jstree( {
    "types": {
        "type_attr": "typ",
        "valid_children": ["ap_ordner_pop", "ap_ordner_apziel", "ap_ordner_erfkrit", "ap_ordner_apber", "ap_ordner_ber", "ap_ordner_beob", "iballg", "ap_ordner_ibb", "ap_ordner_ibartenassoz"],
        "types": {
        "ap_ordner_pop": {
            "valid_children": "pop"
        },
        "pop": {
            "valid_children": ["pop_ordner_tpop", "pop_ordner_popber", "pop_ordner_massnber"],
            "new_node": "neue Population"
        },
        "pop_ordner_tpop": {
            "valid_children": "tpop"
        }

但是我仍然可以将大多数节点放到几乎任何地方. 必须如何做? 还是可以给我指出一个很好的例子?

But I can still drop most nodes nearly anywhere. How must this be done? Or can you point me to a good example?

非常感谢您的帮助.

推荐答案

在目标上,您需要检查是否允许在此处放置对象.似乎您有某种机制可以闻到物体的气味,如下所示:

On the target(s) you would need to check if you are allowed to drop an object there. It seems you have some mechanism to smell the object as you indicated with:

 if (data.rslt.o.attr("typ") === "tpop")

那很好.执行多树操作时,使用该技术将一种对象类型与另一种对象类型区分开.在下面的示例中,我使用源和目标中的类名来进行自己独特的气味测试".不要复制和粘贴,否则会感到困惑.您需要使用自己的测试类型来接受/拒绝从一棵树到另一棵树的拖放操作.我所有的测试都是在crrm check_move函数中完成的.

That's good. Use that technique to discriminate one object type from another when performing a multitree operation. In the example below I use class names from source and target to do my own unique "smell test". Don't copy and paste or you'll get confused. You need to use your own type of test to accept/reject a drag and drop from one tree to another. All of my testing is done in the crrm check_move function.

.jstree({
 "crrm" : {
    input_width_limit : 200,
    move : {
        always_copy     : "multitree", // false, true or "multitree"
        open_onmove     : false,
        default_position: "last",
        check_move      : function (m) { 
                            if(!m.np.hasClass("someClassInTarget")) return false;
                            if(!m.o.hasClass("someClassInSource")) return false;
                            return true;
                          }
    }
 },
 "dnd" : {
    copy_modifier   : $.noop,
    drop_target     : ".someWrapperClassInSource",
    drop_check      : function (data) { return true; },
    drop_finish     : function (data) {
                            $.jstree._reference(this.get_container()).remove($(data.o));
                      },
    drag_target     : ".someClassInSource",
    drag_finish     : function (data) {;},
    drag_check      : function (data) { return { after : false, before : false, inside : true }; }
 },

这篇关于dnd,如何限制删除到某些节点类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆