3

所以我在我的 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 说我还没有定义一个函数,但是我已经在我所有需要定义它的文档中定义了它,你们能否告诉我是否有任何工具可以帮助我找出在哪里它没有定义吗?谢谢!

4

2 回答 2

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
于 2013-08-12T23:31:23.157 回答
0

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

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

据我所知,if 语句没有结束 }。

于 2013-08-12T23:31:17.350 回答