对象不支持属性或方法'children'在JStree中重命名节点时

时间:2012-06-04 06:24:26

标签: javascript jstree

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

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

错误:

  

Microsoft JScript运行时错误:对象不支持属性或方法'children'

我尝试调试,我在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();
            },

1 个答案:

答案 0 :(得分:2)

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