javascript - 我可以访问这个 _normalize 方法吗?

标签 javascript jquery jquery-ui

如果我们查看 jquery.ui.autocomplete 的源代码,他们会得到这个:

$.widget( "ui.autocomplete", {
    // *snip*

    _normalize: function( items ) {
        // assume all items have the right format when the first item is complete
        if ( items.length && items[0].label && items[0].value ) {
            return items;
        }
        return $.map( items, function(item) {
            if ( typeof item === "string" ) {
                return {
                    label: item,
                    value: item
                };
            }
            return $.extend({
                label: item.label || item.value,
                value: item.value || item.label
            }, item );
        });
    },

        // *snip*
});

$.extend( $.ui.autocomplete, {
    escapeRegex: function( value ) {
        return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    },
    filter: function(array, term) {
        var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
        return $.grep( array, function(value) {
            return matcher.test( value.label || value.value || value );
        });
    }
});

我可以用我自己的项目调用 _normalize 方法吗?

我不太确定这一切在内部是如何组合在一起的。我正在尝试像 $.ui.autocomplete._normalize 这样的东西,但这似乎是未定义的。 $.ui.autocomplete.escapeRegex 也是如此,我觉得这很奇怪,因为看起来他们正在那里扩展它......

最佳答案

尝试使用 $.ui.autocomplete.prototype 访问这些成员

关于javascript - 我可以访问这个 _normalize 方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6481300/

相关文章:

javascript - Twitter Bootstrap 导航下拉菜单未扩展到 div 之外

javascript - 如何在浏览器中预取返回 JSON 格式数据的 ajax 调用

javascript - jquery 参数.callee

jquery - 检测 jquery-ui Accordion 打开/关闭状态

javascript - Jquery 嵌套函数不起作用

jQuery 无法删除父级?

javascript - instagram embeds.js 处理程序知道何时加载 iframe

javascript - 更改鼠标单击 Canvas 上的文本

javascript - 当用户进行文件更改时,FileAPI 不会更新文件大小(非 webkit 浏览器)

javascript - 基于对象属性对数组进行排序 - Javascript