javascript - jQuery UI - 这相当于什么?

标签 javascript jquery jquery-ui jquery-plugins jquery-widgets

我正在阅读我正在扩展的 jquery-ui 小部件的源代码,我完全被这一行代码难住了。

this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement

如果我理解正确的话,这意味着上面只能等同于两件事:

this.placeholder["next"]()[0] !== itemElement
this.placeholder["prev"]()[0] !== itemElement

它想做什么?它如何执行数组键?

这是定义 this.placeholder 的地方:

_createPlaceholder: function(that) {
    that = that || this;
    var className,
        o = that.options;

    if(!o.placeholder || o.placeholder.constructor === String) {
        className = o.placeholder;
        o.placeholder = {
            element: function() {

                var nodeName = that.currentItem[0].nodeName.toLowerCase(),
                    element = $( "<" + nodeName + ">", that.document[0] )
                        .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
                        .removeClass("ui-sortable-helper");

                if ( nodeName === "tr" ) {
                    that.currentItem.children().each(function() {
                        $( "<td>&#160;</td>", that.document[0] )
                            .attr( "colspan", $( this ).attr( "colspan" ) || 1 )
                            .appendTo( element );
                    });
                } else if ( nodeName === "img" ) {
                    element.attr( "src", that.currentItem.attr( "src" ) );
                }

                if ( !className ) {
                    element.css( "visibility", "hidden" );
                }

                return element;
            },
            update: function(container, p) {

                // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
                // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
                if(className && !o.forcePlaceholderSize) {
                    return;
                }

                //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
                if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css("paddingTop")||0, 10) - parseInt(that.currentItem.css("paddingBottom")||0, 10)); }
                if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css("paddingLeft")||0, 10) - parseInt(that.currentItem.css("paddingRight")||0, 10)); }
            }
        };
    }

    //Create the placeholder
    that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));

    //Append it after the actual current item
    that.currentItem.after(that.placeholder);

    //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
    o.placeholder.update(that, that.placeholder);

}

如果有人能阐明这一点,我将非常感激。

最佳答案

它正在获取上一个或下一个 DOM 元素。由于 jQuery 返回一个类似数组的对象,因此 [0] 是存储的第一个 DOM 项。

this.placeholder.prev() 

相同
this.placeholder["prev"]()

后者称为 bracket notation .

关于javascript - jQuery UI - 这相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27470961/

相关文章:

javascript - JavaScript 中的保留字列表

javascript - 按日期对 sequelize.js 查询进行排序

javascript - Three.js 不尊重我的常态

javascript - 脚本中模糊的div如何分配悬停点击

jquery - 隐藏选择元素中的选项,在 IE 中不起作用?

JQuery UI 自动完成,选择后的值(通过鼠标)与(通过箭头键)不同

javascript - 如何缩小嵌入式谷歌地图?

jquery - Bootstrap 下拉菜单。悬停时打开,但如何在点击时关闭?

javascript - 为什么 query-ui 可排序功能无法正常工作?

jquery - 是否可以使用jquery函数(例如delegate)来监听jquery ui事件?