0

我正在开发 Codeigniter 框架中的一个项目。我在 Chrome 中收到 Uncaught SyntaxError: Unexpected identifier error,在 Firebug 中我收到 SyntaxError: syntax error,它指向倒数第二个函数末尾的逗号。这是原型中的最后两个函数...

_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;
}

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

4

2 回答 2

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;
}
};
于 2014-02-03T14:58:20.597 回答
0

实际上,我在同一个原型中的前一个函数中有一个注释,它被注释为 /* JS 样式注释 /* 导致错误。

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

于 2014-02-04T14:01:40.453 回答