.bind("move_node.jstree",..-> data.rslt.obj未定义.如何获取节点数据? [英] .bind("move_node.jstree",.. -> data.rslt.obj undefined. How to get node data?

查看:64
本文介绍了.bind("move_node.jstree",..-> data.rslt.obj未定义.如何获取节点数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有用于check_move的自定义功能:

crrm : {
        move : {
            "check_move" : function (m) {

                var p = this._get_parent(m.o);
                if(!p) 
                    return false;
                if(m.cr===-1)
                    return false;
                return true;        
                }

        }   
    },

这似乎按预期工作. 然后,我尝试绑定到"move_node"事件以更新数据库:

.bind("move_node.jstree",function(event,data){
    if(data.rslt.obj.attr("id")==""){
         /* I omitted this snippet from this paste - it's really long and it basically does the same thing as below, just gets the node's id in a more complicated way*/
    } else { 
        controller.moveNode(data.rslt.obj.attr("id"),data.inst._get_parent(this).attr("id"),data.rslt.obj.attr("rel"));
    }   
})

这将导致错误. data.rslt.obj是未定义的.我真的无所适从,我之前绑定过多个事件,而这就是我的工作方式.

如果data.rslt.obj不起作用,如何在move_node事件之后获取节点属性等?

哦,controller.moveNode()是我自己的功能之一,所以如果您想学习jstree,请不要只是复制粘贴.

解决方案

我在问了一下(典型的)后很快就找到了自己问题的答案.

一个人必须使用data.rslt.o.attr("id")而不是-.obj.

我将删除此帖子,但我认为这可能是一个很常见的问题.如果有人有其他想法,请随时删除.

I have a custom functionality for check_move:

crrm : {
        move : {
            "check_move" : function (m) {

                var p = this._get_parent(m.o);
                if(!p) 
                    return false;
                if(m.cr===-1)
                    return false;
                return true;        
                }

        }   
    },

This seems to work as intended. I then try to bind to the "move_node" event to update my database:

.bind("move_node.jstree",function(event,data){
    if(data.rslt.obj.attr("id")==""){
         /* I omitted this snippet from this paste - it's really long and it basically does the same thing as below, just gets the node's id in a more complicated way*/
    } else { 
        controller.moveNode(data.rslt.obj.attr("id"),data.inst._get_parent(this).attr("id"),data.rslt.obj.attr("rel"));
    }   
})

This results in an error. data.rslt.obj is undefined. I'm truly at loss at what to do, I've binded to multiple events before and this is how I've done it.

How can I get node attributes etc after the move_node event, if data.rslt.obj doesn't work?

Oh, the controller.moveNode() is one of my own functions, so don't just copy-paste if you're trying to learn jstree.

解决方案

I found the answer to my own question pretty soon after asking about it (typical).

One must use data.rslt.o.attr("id") instead of -.obj.- An odd inconsistency if you ask me.

I would delete this post, but I think this could be a pretty common problem. If someone thinks otherwise, feel free to delete.

这篇关于.bind("move_node.jstree",..-> data.rslt.obj未定义.如何获取节点数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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