【问题标题】:jqGrid throws "Uncaught Syntax error, unrecognized expression: #"jqGrid 抛出“未捕获的语法错误,无法识别的表达式:#”
【发布时间】:2011-04-30 00:18:16
【问题描述】:

大家好 :) 对于冗长的代码清单,我很抱歉,但我不确定我到底在哪里搞砸了。我正在编写一个仅供内部使用的 jquery 插件,用于编辑访问控制列表。

ACL 编辑器的一个组件是 jqGrid 插件,它是一个出色的网格实现,带有它自己的 AJAX 加载工具等。我以前使用过这个组件,但我以前从未尝试将它用作插件的子组件。 AJAX 请求被正确发送(从我在 Chrome 的调试器中看到的),这让我相信错误不在我的代码中,但我不确定此时该怎么做。

我很抱歉有大量代码,但这是我能想到的最小示例。

/*global jQuery*/
"use strict"; /* Enable ECMAScript 5 Strict Mode if supported */
(function ($) {
    var methods, defaults;

    methods = {
        init: function (options) {
            var sid, pager, enumerateUrl;
            if (this.data('isAclEditor')) {
                $.error('The targeted element is already an ACL Editor.');
            } else {
                this.data('isAclEditor', true);
            }
            this.data('options', $.extend(true, {}, defaults, options));
            /*
             <div class="ui-jqgrid ui-widget ui-widget-content">
                <div class="ui-jqgrid-titlebar ui-widget-header ui-helper-clearfix">
                    <span class="ui-jqgrid-title">TITLE</span>
                </div>
                <table class="sidList"></table>
                <div class="sidPager"></div>
                <div class="privSlideout" style="display:none;">
                    <table cellspacing="0" cellpadding="0" border="0">
                        <thead>
                            <tr>
                                <th class="ui-th-column ui-state-default" colspan="3" class="privLabel"></th>
                            </tr>
                            <tr>
                                <th class="ui-th-column ui-state-default" style="width: 50px;">Allow</th>
                                <th class="ui-th-column ui-state-default" style="width: 50px;">Deny</th>
                                <th class="ui-th-column ui-state-default" style="width: 520px;">Privilege</th>
                            </tr>
                        </thead>
                        <tbody class="privTable">
                        </tbody>
                    </table>
                    <button class="btnOk">Ok</button>
                    <button class="btnCancel">Cancel</button>
                </div>
                <div style="display:none;" class="newPrivPicker">
                    <div style="font-size: 10pt">
                        <table class="newPrivTable"></table>
                        <div class="newPrivPager"></div>
                    </div>
                </div>
             </div>
             */
            this.html('<div class="ui-jqgrid ui-widget ui-widget-content"><div class="ui-jqgrid-titlebar ui-widget-header ui-helper-clearfix"><span class="ui-jqgrid-title">' + this.data('options').title + '</span></div><table class="sidList"></table><div class="sidPager"></div><div class="privSlideout" style="display:none;"><table cellspacing="0" cellpadding="0" border="0"><thead><tr><th class="ui-th-column ui-state-default" colspan="3" class="privLabel"></th></tr><tr><th class="ui-th-column ui-state-default" style="width: 50px;">Allow</th><th class="ui-th-column ui-state-default" style="width: 50px;">Deny</th><th class="ui-th-column ui-state-default" style="width: 520px;">Privilege</th></tr></thead><tbody class="privTable"></tbody></table><button class="btnOk">Ok</button><button class="btnCancel">Cancel</button></div><div style="display:none;" class="newPrivPicker"><div style="font-size: 10pt"><table class="newPrivTable"></table><div class="newPrivPager"></div></div></div></div>');
            pager = $('.sidPager', this);
            enumerateUrl = this.data('options').aclControllerUrl + '/enumerate/aclid/' + this.data('options').aclId;
            sid = $('.sidList', this).jqGrid({
                url: enumerateUrl,
                datatype: 'json',
                mtype: 'GET',
                colNames: ['Type', 'Name'],
                colModel: [
                    {name: 'type', index:'type', width: 20, align: 'center', sortable: false},
                    {name: 'displayName', index:'displayName', align: 'center', sortable: false}
                ],
                rowNum: 10,
                rowList: [10, 100, 1000],
                autowidth: true,
                height: 'auto',
                forceFit: true,
                gridview: true,
                pager: pager
            });
            sid.navGrid(pager, {
                edit:false,
                add:false,
                del:false,
                search:false,
                refresh:true,
                refreshtitle: 'Refresh Users and Groups'
            });
            return this;
        }
    };

    defaults = {
        aclId: 0,
        title: 'Permissions Editor',
        aclControllerUrl: ''
    };

    $.fn.acleditor = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' +  method + ' does not exist on jQuery.AclEditor.');
        }
        return null;
    };

}(jQuery));

为什么我在 Jquery.js 的第 75 行收到“未捕获的语法错误,无法识别的表达式:#”?

哦,我正在使用 jqgrid 3.8.1 和 jquery 1.4.2。

编辑:返回的 JSON 是:

{"rows":[{"id":"7109766F-DC8A-4134-8C1F-02F87A72DE9C","cell":["Group","Developers"]},{"id":"22EEB0C5-6792-4C24-8047-B187D38F63EC","cell":["Group","Users"]}],"page":1,"total":1,"records":2}

【问题讨论】:

    标签: jquery jquery-plugins jqgrid


    【解决方案1】:

    好的,对不起大家。发现了问题——原来 jqGrid 保存了 table 标记的 ID,然后稍后使用该标记引用 table。给 &lt;table&gt; 一个 ID 可以解决问题。

    【讨论】:

    • 遇到同样的错误,找了一个多小时的错误。这个答案救了我,谢谢!此外,对于旧版本的 jqGrid,这不是问题。当我从 3.5.3 升级到 3.8.2 时它停止工作。
    • 只是为了帮助澄清 - 他说的是这样做
      而不是这个
    • @010110110101:我确实说的是 ID,而不是班级。 :)
    • 谢谢你,比利,大大节省了时间。多么愚蠢的错误。如果 jqGrid 需要表有一个id,如果没有,它应该提供一个,或者初始化失败并显示有意义的错误消息。
    • @T.J.Crowder:同意。 OTOH,它真的根本不需要 ID,只需直接保存对它需要的 DOM 元素的引用。
    【解决方案2】:

    如果有人使用“jqGrid for ASP.NET MVC”来搜索此错误。我在保存“添加新”对话框时遇到了这个确切的错误。

    事实证明,我没有设置“MyGridModel.AddDialogSettings.CloseAfterAdding = true;”

    【讨论】:

      猜你喜欢
      • 2013-10-10
      • 2016-05-28
      • 1970-01-01
      • 2017-11-24
      • 2017-06-06
      • 2019-02-18
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      相关资源
      最近更新 更多