gpt4 book ai didi

javascript - jqGrid 创建单独的函数

转载 作者:行者123 更新时间:2023-12-03 12:00:53 32 4
gpt4 key购买 nike

如何将 function subGridRowExpanded 分离到另一个函数并转换为 subGridRowExpanded :

subGrid: Hierarchy,

subGridOptions : {
plusicon : "ace-icon fa fa-plus center bigger-110 blue",
minusicon : "ace-icon fa fa-minus center bigger-110 blue",
openicon : "ace-icon fa fa-chevron-right center orange" },
subGridRowExpanded: function subGridRowExpanded(subgrid_id, row_id)
{
//somecode
}

最佳答案

我不确定我是否正确理解你的问题。我想您不想使用匿名函数作为subGridRowExpanded的值。如果您在 JavaScript 中有两种标准方式:

1) 定义变量并为其分配匿名函数。

var mySubGridRowExpanded = function (subgridDivId, rowId) {
// here one can use 'this' to access to the grid
// for example
//
// var mainGridPrefix = $(this).jqGrid("getGridParam", "idPrefix"),
// pureRowId = $.jgrid.stripPref(mainGridPrefix, rowId);

// create empty table and div with unique ids which we construct base on
// id of subgrid div created by jqGrid before calling of mySubGridRowExpanded
var $subgrid = $("<table id='" + subgridDivId + "_t'></table>" +
"<div id='" + subgridDivId + "_p" + "'></div>");

// append the subgrid to the subgrid div
$subgrid.appendTo("#" + $.jgrid.jqID(subgridDivId));

// create subgrid as jqGrid
$subgrid.jqGrid({
...
});
};

2) 像您在其他计算机语言中所知道的那样定义命名的函数。使用术语function statement在 Javascript 中的情况。前一种方式(使用 var mySubGridRowExpanded = function (subgridDivId, rowId) {...};)一个名称 function expression 。您可以使用该函数的名称作为 jqGrid 的 subGridRowExpanded 属性的值。

function mySubGridRowExpanded (subgridDivId, rowId) {
// the same code as above with small disadvantage
// that one could have warnings by some JavaScript
// validators that 'this' could be undefined.
}

在这两种情况下,您都可以使用 jqGrid 选项,例如

subGrid: true,
subGridOptions : {
plusicon : "ace-icon fa fa-plus center bigger-110 blue",
minusicon : "ace-icon fa fa-minus center bigger-110 blue",
openicon : "ace-icon fa fa-chevron-right center orange" },
subGridRowExpanded: mySubGridRowExpanded

正如我在我最喜欢的语言中所知道的那样,JavaScript 有另一种函数语义,因为人们定义类和对象的方式不同。所以我个人更喜欢第一种方式(函数表达式)定义mySubGridRowExpanded function (var mySubGridRowExpanded = function (subgridDivId, rowId) {...};)

关于javascript - jqGrid 创建单独的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25427162/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com