weixin_33691598 2017-05-04 14:24 采纳率: 0%
浏览 53

自动完成中的jQuery错误

Im getting Uncaught TypeError: Cannot use 'in' operator to search for 'length' in on a autocomplete field. This is the code:

    enable_autocomplete: function() {
    $( 'input.fm-autocomplete:visible' ).each( function() {
        if ( !$( this ).hasClass( 'fm-autocomplete-enabled' ) ) {
            var ac_params = {};
            var $el = $( this );
            var $hidden = $el.siblings( 'input[type=hidden]' ).first();
            ac_params.select = function( e, ui ) {
                e.preventDefault();
                $el.val( ui.item.label );
                $hidden.val( ui.item.value ).trigger( 'change' );
            };
            ac_params.focus = function( e, ui ) {
                e.preventDefault();
                $el.val( ui.item.label );
            }
            if ( $el.data( 'action' ) ) {
                ac_params.source = function( request, response ) {
                    // Check for custom args
                    var custom_args_js_event = $el.data( 'customArgsJsEvent' );
                    var custom_data = '';
                    if ( 'undefined' !== typeof custom_args_js_event && null !== custom_args_js_event ) {
                        var custom_result = $el.triggerHandler( custom_args_js_event );
                        if ( 'undefined' !== typeof custom_result && null !== custom_result ) {
                            custom_data = custom_result;
                        }
                    }

                    $.post( ajaxurl, {
                        action: $el.data( 'action' ),
                        fm_context: $el.data( 'context' ),
                        fm_subcontext: $el.data( 'subcontext' ),
                        fm_autocomplete_search: request.term,
                        fm_search_nonce: fm_search.nonce,
                        fm_custom_args: custom_data
                    }, function( result ) {
                        console.log( result );
                        $.parseJSON( response( result ) );
                    } );
                };

All other questions related to this error suggested a $.parseJSON but it's not working for me. This is the console.log of result when i type eco:

[{"label":"Economy Talks","value":1480},{"label":"Economy","value":212},{"label":"Economy motors","value":2038},{"label":"Telecomunica\u00e7\u00f5es","value":402}]

Console.log of response:

function (){return a.apply(b||this,c.concat(e.call(arguments)))}

It finds the right suggestions but then i get Uncaught TypeError: Cannot use 'in' operator to search for 'length' in and i'm not able to select any option. Any ideas how to fix this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000