意外的输入结束(第1行)和未定义的功能?

时间:2013-08-12 23:23:09

标签: javascript function encoding input

所以我在JS中输入了意想不到的结尾,它在第1行,我真的无法理解它是什么,这里是代码:

window.HandlePageCommand = function (commandName) {

    document.getElementById("buffer").innerHTML = commandName + " | " + window.ActiveForm.Name;
    var activeForm = window.ActiveForm;
    var call;
    var callback;
    var requestData;
    var grid;

    if (commandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (commandName === "ADD_PERIOD") {

        target = activeForm.Sections[1];
        window.SelectedState = {};
        activeForm.BindUI(window.SelectedState);
        grid = window.RegisteredControls.Grids["Semestres"];

        grid.AddedEntities = [];
        grid.DeletedEntities = [];
        grid.Databind([]);
        Exertus.MainModalPanel.Show("Detalle", target);
        return;
    }

    if (commandName === "ADD_MATERIAL") {

        target = activeForm.Sections[1];
        window.SelectedState = {};
        activeForm.BindUI(window.SelectedState);
        grid = window.RegisteredControls.Grids["GRID_DE_MATERIALES"];

        grid.AddedEntities = [];
        grid.DeletedEntities = [];
        grid.Databind([]);
        Exertus.MainModalPanel.Show("DETAIL", target);
        return;
    }


    if (activeForm.Name === "Periodos") {

        callback = function (responseData) {
            var innerGrid = window.RegisteredControls.Grids["Semestres"];
            var responseInfo = jQuery.parseJSON(responseData);
            innerGrid.Databind(responseInfo.Users);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }

        if (window.ActiveForm.Validate() != true) {
            return;
        }

        window.SetLoading(true);
        call = new Exertus.ServerCall("MainWebModule");
        this.SelectedPeriod = this.SelectedPeriod || {};
        activeForm.BindEntity(this.SelectedPeriod);
        grid = window.RegisteredControls.Grids["Semestres"];

        requestData = {
            PeriodData: this.SelectedPeriod
        }
        call.Execute("SavePeriodChanges", requestData, callback);
        return;

    }

    if (commandName === "GUARDAR") {

        if (activeForm.Name === "Factores de Venta 1") {
            var callback = function (responseData) {
                window.OriginalFactors = jQuery.extend({}, window.FactorsInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.FactorsInfo = window.FactorsInfo || {};
            activeForm.BindEntity(window.FactorsInfo);
            call.Execute("SaveFactors", window.FactorsInfo, callback);
            return;
        }


            if (commandName === "SAVE") {

        if (activeForm.Name === "Direcciones") {
            var callback = function (responseData) {
                window.OriginalAddress = jQuery.extend({}, window.AddressInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.AddressInfo = window.AddressInfo || {};
            activeForm.BindEntity(window.AddressInfo);
            call.Execute("SaveAddress", window.AddressInfo, callback);
            return;
        }

            if (commandName === "SAVE") {

        if (activeForm.Name === "Materiales") {
            var callback = function (responseData) {
                window.OriginalMaterials = jQuery.extend({}, window.MaterialsInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.MaterialsInfo = window.MaterialsInfo || {};
            activeForm.BindEntity(window.MaterialsInfo);
            call.Execute("SaveMaterials", window.MaterialsInfo, callback);
            return;
        }

    if (commandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (commandName === "GUARDAR") {

        if (activeForm.Name === "Factores de Venta 2") {
            var callback = function (responseData) {
                window.OriginalFactorsBoundaries = jQuery.extend({}, window.FactorsBoundariesInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.FactorsBoundariesInfo = window.FactorsBoundariesInfo || {};
            activeForm.BindEntity(window.FactorsBoundariesInfo);
            call.Execute("SaveFactors", window.FactorsBoundariesInfo, callback);
            return;
        }

    if (commandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (commandName === "SAVE_CHANGES") {
        var callback = function (responseData) {
            var innerGrid = arguments.callee.Grid;
            var entities = jQuery.parseJSON(responseData);
            window.FamilyProductsTypes = entities;

            innerGrid.AddedEntities = [];
            innerGrid.ModifiedEntities = {};
            innerGrid.DeletedEntities = [];

            innerGrid.Databind(entities);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }


        var grid = window.RegisteredControls.Grids["Artículos"];

        if (grid.HasChanges() != true) {
            Exertus.MainModalPanel.ShowText("Notificación", "No hay cambios que guardar.");
            return;
        }

        if (grid.Validate() != true) {
            return;
        }

        if (commandName === "DISCARD_CHANGES") {
        var callback = function () {
            var innerGrid = arguments.callee.Grid;

            innerGrid.AddedEntities = [];
            innerGrid.DeletedEntities = [];
            innerGrid.Databind(innerGrid.OriginalEntities);

            jQuery(innerGrid.Root).attr("class", "");
            delete window.ModifiedGrids[innerGrid.Name];

            Exertus.MainModalPanel.ShowText("Notificación", "Se han descartado los cambios.");
        }

        var grid = window.RegisteredControls.Grids.Artículos;
        callback.Grid = grid;
        Exertus.MainModalPanel.Confirm("Confirmación", "¿Confirma que desea descartar los cambios?", callback);
    }

    if (commandName === "CANCELAR") {
        var callback = function () {
            var innerGrid = arguments.callee.Grid;

            innerGrid.AddedEntities = [];
            innerGrid.DeletedEntities = [];
            innerGrid.Databind(innerGrid.OriginalEntities);

            jQuery(innerGrid.Root).attr("class", "");
            delete window.ModifiedGrids[innerGrid.Name];

            Exertus.MainModalPanel.ShowText("Notificación", "Se han cancelado los cambios.");
        }

        var grid = window.RegisteredControls.Grids["Carga De Archivos"];
        callback.Grid = grid;
        Exertus.MainModalPanel.Confirm("Confirmación", "¿Confirma que desea cancelar los cambios?", callback);
    }

}

错误标记在第一行,第一行是空的,所以我不知道那是什么。

我的另一个问题是Chrome说我没有定义一个功能,但是我想在我需要定义的所有文档中定义它,你能告诉我是否有任何工具可以帮助我找出它没有定义的地方? 谢谢!

2 个答案:

答案 0 :(得分:5)

对于代码段中的所有{,它都会在5 }左右丢失。

这会创建一个SyntaxError,因为解析器正在尝试匹配每对,并且在它可以之前用完代码(因此,“意外结束”)。此错误还会使function定义无效,这就是为什么它可能尝试使用它的其他代码不存在。

要获得帮助的工具,您可以尝试JSHint。它可能有些严格,但会扫描一段代码并记下它认为有用的任何建议。并且,它是可配置的,因此扫描复选框列表以调整它给出的警告类型。

尽管如此,最好的猜测是他们开始缺席:

if (commandName === "GUARDAR") {

    if (activeForm.Name === "Factores de Venta 1") {
        var callback = function (responseData) {
            window.OriginalFactors = jQuery.extend({}, window.FactorsInfo);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }

        if (window.ActiveForm.Validate() != true) {
            return;
        }

        window.SetLoading(true);
        var call = new Exertus.ServerCall("MainWebModule");
        window.FactorsInfo = window.FactorsInfo || {};
        activeForm.BindEntity(window.FactorsInfo);
        call.Execute("SaveFactors", window.FactorsInfo, callback);
        return;
    }

//} <-- missing

答案 1 :(得分:0)

我想你忘记了一个括号,看看附近的代码:

if (commandName === "DISCARD_CHANGES") {
var callback = function () {

就我所见,if语句没有关闭}。