jqGrid.info_dialog 不是函数,我必须调用 extend 吗?

jqGrid.info_dialog is not a function, do I have to call extend?

我尝试在我的 jqGrid 上使用 info_dialog,但在控制台中看到 TypeError: $(...).jqGrid.info_dialog is not a function

我 (!) 没有定义我自己的 info_dialog 函数。但是我可以在 $.extend($.jgrid, ... 中看到它,例如 here,所以我希望它默认可用。

info_dialog : function(caption, content,c_b, modalopt) {
        var mopt = {
            width:290,
            height:'auto',

我是否必须以某种方式为网格启用它?或者我还需要做什么才能使用定义的版本 here(在我的网格上调用 extend?..)

使用来自 https://cdnjs.com/libraries/jqgrid
的 4.6.0 现在使用 https://cdnjs.com/libraries/free-jqgrid 4.14.1

jqGrid不仅定义了"standard"方法,可以用作$("#grid").jqGrid("methodName", ...)$("#grid").methodName(...),还定义了其他一些方法。 "standard" 方法将在 $.fn.jqGrid.methodName 下注册(例如 $.fn.jqGrid.editGridRow 函数),如果在 $.jgrid.no_legacy_api = true; 之前没有指定 $.jgrid.no_legacy_api = true;,则在 [=17] 下=] 也是。

换句话说,只存在全局对象 $.fn.jqGrid$.fn,其中包含 "standard" jqGrid 方法。

其他一些方法列表将在 $.jgrid 下注册,而不是 $.fn.jqGrid$.fninfo_dialog 就是这种方法的一个例子。因此应该使用$.jgrid.info_dialog$.jgrid.jqID$.jgrid.htmlEncode$.jgrid.randId等来使用这样的方法。大多数方法不需要初始化this(如$.jgrid.randId()$.jgrid.jqID("some.text")),但有些方法要求this初始化为DOM网格(用于生成网格的空 <table>)。

例如,您可以使用

$grid.jqGrid("navButtonAdd", "#pager", {
    caption: "Test",
    onClickButton: function () {
        $.jgrid.info_dialog.call(this,
            "Warning with two buttons",
            "Click the `test` button",
            "Close",
            {
                buttons: [
                    {
                        text: "\"text\" button",
                        id: "buttid",
                        onClick: function() {
                            alert("click...");
                        }
                    }
                ]
            }
        );
    }
});

请参阅我开发的 https://jsfiddle.net/OlegKi/xLrbdspo/. I use in the demo free jqGrid fork,但同样适用于您使用的 jqGrid 的复古版本 4.6。

最后的评论。如果您知道 TypeScript 的语法,您可以在 free-jqgrid.d.ts answers on many of questions like the usage of info_dialog. The methods and properties of $.jgrid are described here (inclusive info_dialog). You will find here 中找到另外一些方法 $.fmatter$.jqm$.jqDnR$.unformat,它们是 jqGrid 的一部分和 $.jgrid.

一样