对象不支持属性或方法“子项” 在 JStree 中重命名节点时

Object doesn't support property or method 'children' When renaming node in JStree

本文关键字:JStree 重命名 节点 子项 属性 不支持 方法 对象      更新时间:2023-09-26

我正在尝试使用以下代码重命名节点:

  'rename': function (t) 
    {
    $("#demo").jstree("rename"); 
    }

错误:

Microsoft JScript 运行时错误:对象不支持属性或方法"子项"

我尝试调试,但在jquery.jstree的以下代码中出现上述错误.js

文件

错误在第 w1 = obj.children("ins").width(), 行。

_fn : {
            _show_input : function (obj, callback) {
                obj = this._get_node(obj);
                var rtl = this._get_settings().core.rtl,
                    w = this._get_settings().crrm.input_width_limit,
                    w1 = obj.children("ins").width(),
                    w2 = obj.find("> a:visible > ins").width() * obj.find("> a:visible > ins").length,
                    t = this.get_text(obj),
                    h1 = $("<div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body"),
                    h2 = obj.css("position","relative").append(
                    $("<input />", { 
                        "value" : t,
                        "class" : "jstree-rename-input",
                        // "size" : t.length,
                        "css" : {
                            "padding" : "0",
                            "border" : "1px solid silver",
                            "position" : "absolute",
                            "left"  : (rtl ? "auto" : (w1 + w2 + 4) + "px"),
                            "right" : (rtl ? (w1 + w2 + 4) + "px" : "auto"),
                            "top" : "0px",
                            "height" : (this.data.core.li_height - 2) + "px",
                            "lineHeight" : (this.data.core.li_height - 2) + "px",
                            "width" : "150px" // will be set a bit further down
                        },
                        "blur" : $.proxy(function () {
                            var i = obj.children(".jstree-rename-input"),
                                v = i.val();
                            if(v === "") { v = t; }
                            h1.remove();
                            i.remove(); // rollback purposes
                            this.set_text(obj,t); // rollback purposes
                            this.rename_node(obj, v);
                            callback.call(this, obj, v, t);
                            obj.css("position","");
                        }, this),
                        "keyup" : function (event) {
                            var key = event.keyCode || event.which;
                            if(key == 27) { this.value = t; this.blur(); return; }
                            else if(key == 13) { this.blur(); return; }
                            else {
                                h2.width(Math.min(h1.text("pW" + this.value).width(),w));
                            }
                        },
                        "keypress" : function(event) {
                            var key = event.keyCode || event.which;
                            if(key == 13) { return false; }
                        }
                    })
                ).children(".jstree-rename-input"); 
                this.set_text(obj, "");
                h1.css({
                        fontFamily      : h2.css('fontFamily')      || '',
                        fontSize        : h2.css('fontSize')        || '',
                        fontWeight      : h2.css('fontWeight')      || '',
                        fontStyle       : h2.css('fontStyle')       || '',
                        fontStretch     : h2.css('fontStretch')     || '',
                        fontVariant     : h2.css('fontVariant')     || '',
                        letterSpacing   : h2.css('letterSpacing')   || '',
                        wordSpacing     : h2.css('wordSpacing')     || ''
                });
                h2.width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
            },

问题是因为我在单击重命名之前没有选择文件夹。当我选择文件夹并重命名它时,一切都很好