Uncaught SyntaxError:意外的标识符

时间:2014-02-03 14:44:57

标签: javascript jquery codeigniter rightnow-crm

我正在使用Codeigniter框架中的项目。我收到了一个Uncaught SyntaxError:Chrome中出现了意外的标识符错误,而在Firebug中我收到了一个SyntaxError:语法错误,该错误指向我倒数第二个函数结束时的逗号。以下是Prototype中的最后两个函数......

_getAeList: function(sippno) {

    $('#ae_Values').html('<div style="width:100%;"><img src="/euf/assets/images/loading.gif"/></div>');

    var listType = sippno;
    $.ajax({
        type: "POST",
        url: "/ci/ajaxCustom/AdaptEquipList",
        cache: false,
        data: "listType=" + sippno,
        datatype: "json",
        success: function(json){

            jQuery.extend(adaptequip, json);

            $("#aeSubtext").show();
            $("#ae_Values").html("<select multiple='multiple' id='adaptequip' name='adaptequip' ></select>");

            /* For compatibility with <=IE8 and other browsers that don't support Object.keys() */
            if (!Object.keys) Object.keys = function(o) {
                if (o !== Object(o))
                    throw new TypeError('Object.keys called on a non-object');
                var k=[],p;
                for (p in o) if (Object.prototype.hasOwnProperty.call(o,p)) k.push(p);
                return k;
            }

            Object.keys(adaptequip)
                .sort(function(a,b) {
                    return b.localeCompare(a)
                    })
                for(key in adaptequip) {
                    var val = adaptequip[key];

                    var sippnohand = ["MVAR","STAR"];
                    var inarray = $.inArray(sippno, sippnohand);

                    /* Check the code against array of no hand controls */
                    if(inarray > -1 && val.aeid == 1) {
                        $('#adaptequip').append('<option value="' + val.aeid + '" disabled>' + val.aename + '</option>');
                    } else {
                        $('#adaptequip').append('<option value="' + val.aeid + '">' + val.aename + '</option>');
                    }

                }

            $('#ae_Values').append('</select>');
            $("#selected_ae").show();

            $("#adaptequip").click("option", function() {
                $('#selected_ae_list').empty();
                RightNow.Widget.AdaptiveEquipment.prototype._createAeArray()
            });
        }
    });
}, <---------- Here is the comma that firebug points to

_createAeArray: function() {

    var aeArray = [];
    var textvals = [];

    $('#adaptequip :selected').each(function(i, selected){
        textvals[i] = $(this).text();
        aeArray[i] = $(this).val();
    });

        for (var i=0,l=textvals.length; i<l; i++) {
            $('#selected_ae_list').append(textvals[i] + '<br/>');
        }

        /* Check to see if AE items are selected and display a notification */
        if (textvals.length === 0) {
            $("#warning_select_ae").html('<img src="/euf/assets/images/orangeex.png" height="15"/> Please select at least one option.');
        } else {
            $("#warning_select_ae").html('<img src="/euf/assets/images/check.png" height="15"/>');
        }

        /* Apply aeArray to aeValues input form */
        $('#aeValues').val(aeArray);
        sippcode.no = sippno;
}

逗号应该在那里,所以我得到的错误似乎很模糊。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

您需要在具有可以逗号分隔的属性的特定Javascript对象下包含上述结构。

请参阅以下代码

var objStructure = {
_getAeList: function(sippno) {

    $('#ae_Values').html('<div style="width:100%;"><img src="/euf/assets/images/loading.gif"/></div>');

    var listType = sippno;
    $.ajax({
        type: "POST",
        url: "/ci/ajaxCustom/AdaptEquipList",
        cache: false,
        data: "listType=" + sippno,
        datatype: "json",
        success: function(json){

            jQuery.extend(adaptequip, json);

            $("#aeSubtext").show();
            $("#ae_Values").html("<select multiple='multiple' id='adaptequip' name='adaptequip' ></select>");

            /* For compatibility with <=IE8 and other browsers that don't support Object.keys() */
            if (!Object.keys) Object.keys = function(o) {
                if (o !== Object(o))
                    throw new TypeError('Object.keys called on a non-object');
                var k=[],p;
                for (p in o) if (Object.prototype.hasOwnProperty.call(o,p)) k.push(p);
                return k;
            }

            Object.keys(adaptequip)
                .sort(function(a,b) {
                    return b.localeCompare(a)
                    })
                for(key in adaptequip) {
                    var val = adaptequip[key];

                    var sippnohand = ["MVAR","STAR"];
                    var inarray = $.inArray(sippno, sippnohand);

                    /* Check the code against array of no hand controls */
                    if(inarray > -1 && val.aeid == 1) {
                        $('#adaptequip').append('<option value="' + val.aeid + '" disabled>' + val.aename + '</option>');
                    } else {
                        $('#adaptequip').append('<option value="' + val.aeid + '">' + val.aename + '</option>');
                    }

                }

            $('#ae_Values').append('</select>');
            $("#selected_ae").show();

            $("#adaptequip").click("option", function() {
                $('#selected_ae_list').empty();
                RightNow.Widget.AdaptiveEquipment.prototype._createAeArray()
            });
        }
    });
}, // comma separation will works now
_createAeArray: function() {

    var aeArray = [];
    var textvals = [];

    $('#adaptequip :selected').each(function(i, selected){
        textvals[i] = $(this).text();
        aeArray[i] = $(this).val();
    });

        for (var i=0,l=textvals.length; i<l; i++) {
            $('#selected_ae_list').append(textvals[i] + '<br/>');
        }

        /* Check to see if AE items are selected and display a notification */
        if (textvals.length === 0) {
            $("#warning_select_ae").html('<img src="/euf/assets/images/orangeex.png" height="15"/> Please select at least one option.');
        } else {
            $("#warning_select_ae").html('<img src="/euf/assets/images/check.png" height="15"/>');
        }

        /* Apply aeArray to aeValues input form */
        $('#aeValues').val(aeArray);
        sippcode.no = sippno;
}
};

答案 1 :(得分:0)

我实际上在同一原型中的前一个函数中有一个注释,该注释使用了一个而不是/ * JS样式的注释/ *来导致错误。

奇怪的是,在倒数第二个函数之后,firebug指向逗号...我不确定浏览器是如何处理字符导致该错误的。