【问题标题】:jQGrid error when firing edit form触发编辑表单时出现jQGrid错误
【发布时间】:2017-01-03 03:15:11
【问题描述】:

我正在使用最新版本的免费 jQGrid 和 jQuery Migrate 1.4.1(1.6.x 到 1.9.2)和 jQuery UI 1.12.1。 更新 jQuery / jQuery UI 编辑表单后不再工作!

代码:

onInitializeForm: function(formid) {
    var form = $(formid).attr('id').split('-').pop();
    var id = $(formid).find('#id_g').val();
    var bt_gerar = $('<input />').attr('type', 'button').val('Gerar').click(function() {
        $(formid).find('input[name="senha"]').val(gerarPassword());
    });
    if (form === 'laudos') $(formid).find('input[name="senha"]').after(bt_gerar);
    if (form === 'usuarios') $(formid).find('input[name="senha"]').val('');
    $(formid).find('input[name="criacao"], input[name="exclusao"], input[name="data"]').datepicker({
        dateFormat: 'dd/mm/yy'
    });
    /* UPLOAD LAUDO */
    var base_url = window.location.protocol + "//" + window.location.host + "/_dev/";
    $('#arquivo').uploadify({
        'swf'  : base_url + 'admin/js/uploadify-new/uploadify.swf',
        'uploader'    : base_url + 'admin/js/uploadify-new/uploadify.php?laudo=true',
        'cancelImage' : base_url + 'admin/img/cancel.png',
        'buttonImage' : base_url + 'admin/img/upload_mini.png',
        'wmode'     : 'transparent',
        'width'     : '20',
        'height'    : '20',
        'auto'      : true,
        'multi'     : false,
        'fileExt'   : '*.pdf',
        'fileDesc'  : 'Arquivo PDF (.PDF)',
        'onComplete': function(event, ID, fileObj, response, data) {
            $('#arquivo').before($('<input />').attr({type:'text',id:'arquivo_temp',class:'FormElement',name:'arquivo',value:response,role:'textbox'}));
            $('#arquivo, #arquivoUploader, #arquivoQueue').remove();
            $('#arquivo_temp').attr('id','arquivo').hide();
            $('#arquivo').after($('<img />').attr({src:'/laudos/pdf.png',id:'arquivo_icone'}));
        }
    });

错误:

TypeError: $(...).closest(...).attr(...).replace is not a function

文件: jquery.jqgrid.src.js19319

代码错误行:

$id = $(this).closest("table.ui-jqgrid-btable").attr("id").replace(/_frozen([^_]*)$/, "$1")

有灯吗? 谢谢你!

【问题讨论】:

    标签: javascript jquery jqgrid free-jqgrid


    【解决方案1】:

    请指定您使用的 jqGrid 的确切版本。 jquery.jqgrid.src.jsfree jqGrid 4.13.6 的第 19319 行包含 var insertPrefixAndSuffix = function (sOutput, opts) {(请参阅 here)。声明“我正在使用最新版本的免费 jQGrid”并没有提供足够的信息。

    您发布的$id = $(this).closest("table.ui-jqgrid-btable").attr("id").replace(/_frozen([^_]*)$/, "$1") 行在free jqGrid 4.13.5 版本中的行号为19319。代码在$.fn.fmatter.rowactions 内。因此,您在使用formatter: "actions" 时可能会遇到一些问题,但是您没有将colModel 包含在相应的列中。 $.fn.fmatter.rowactions 方法将在动作按钮的onclick 中调用,该方法必须在 jqGrid 内部,其中必须有 ui-jqgrid-btable 类。

    我很难猜到你为什么会得到这个错误。要么您对 jqGrid 类进行了一些非法修改(例如删除 ui-jqgrid-btable 类),要么将网格内容(包括操作按钮)移到 jqGrid 内容或其他一些奇怪的东西之外。无论如何,您应该包含colModel 列的定义,它使用formatter: "actions"

    顺便说一下,免费的 jqGrid 支持template: "actions",你可以用它来代替formatter: "actions"template: "actions"是以下设置的快捷方式

    formatter: "actions", align: "center", label: "", autoResizable: false, frozen: true,
    fixed: true, hidedlg: true, resizable: false, sortable: false,
    search: false, editable: false, viewable: false
    

    width 设置,哪个值取决于jqGrid的其他一些选项。大多数属性都严格推荐用于formatter: "actions" 列(即使对于旧版本的jqGrid)。

    我建议您更新到免费的 jqGrid 4.13.6 并将formatter: "actions" 替换为template: "actions"(或者在操作列中添加editable: false 和其他上述属性)。我希望它能解决您的问题。

    【讨论】:

      猜你喜欢
      • 2015-12-15
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      相关资源
      最近更新 更多