2010-10-25 150 views
19

大家好:)對於長代碼列表,我很抱歉,但我不確定在哪裏搞砸了。我正在編寫一個僅供內部使用的jquery插件來編輯訪問控制列表。jqGrid拋出「未捕獲的語法錯誤,無法識別的表達式:#」

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行中得到「Uncaught Syntax error,unrecognized expression:#」?

哦,我正在使用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} 

回答

48

好了,對不起大家。發現問題 - 事實上,jqGrid保存表標記的ID,然後使用該標記引用表。給一個ID編號<table>解決了這個問題。

+0

有同樣的錯誤,找了一個多小時的錯誤。這個答案拯救了我,謝謝!另外,這對jqGrid的舊版本來說不是問題。當我從3.5.3升級到3.8.2時,它停止工作。 – 2011-02-09 22:24:14

+1

只是爲了澄清 - 他正在談論做這個

而不是這個
010110110101 2011-08-20 19:02:48

+1

@ 010110110101:我確實說過ID,而不是class。 :) – 2011-08-21 15:18:56

-1

如果有人曾經用「jqGrid for ASP.NET MVC」來搜索這個錯誤。我在保存「添加新對話框時遇到了這個確切的錯誤。

事實證明,我沒有設置「MyGridModel.AddDialogSettings.CloseAfterAdding = true;」

相關問題