.bind(“move_node.jstree”,.. -> data.rslt.obj undefined. How to get node data?

≯℡__Kan透↙ 提交于 2019-12-07 03:27:01

问题


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.


回答1:


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.




回答2:


if(!p)
  return false;
if(m.cr===-1)
  return false;

return true;

next time try to do it like this:

return (p && m.cr !== -1);


来源:https://stackoverflow.com/questions/6110708/bindmove-node-jstree-data-rslt-obj-undefined-how-to-get-node-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!