jqGrid TreeGrid找到节点的父节点
我想获取jqGrid树中某行的parentId。下面是示例代码jqGrid TreeGrid找到节点的父节点
beforeSelectRow: function (rowid, e) {
var $this = $(this);
var localData = $this.jqGrid("getLocalRow", rowid);
var parentNode = $this.jqGrid("getNodeParent", localData);
}
我得到parentNode为对象,但如果我试图让alert(parentNode.id)
,则返回null ..
我错了在这里做什么?
可能区分大小写?
alert(parentNode.ID)
我相信你正在使用的jqGrid(3.7)的旧版本,因为( “getNodeParent”)都不再像版本3.7.x(http://www.trirand.com/jqgridwiki/doku.php?id=wiki:treegrid)的工作。 你可以尝试使用:
var record = $(”#grid_id”).getRowData(rowid); console.log(record.ID)
,而不是如果你正在使用的jqGrid的新版本。
感谢您的回应。我使用的是最新版本的jqgrid(4.x.),并且这两种方法都可以通过getNodeParent或getRowData来获得id工作,console.log(record.ID)也可以正常工作,但是我想获得父行的ID ..我该怎么做? –
我不知道我是否遵循。但是如果你现在使用rowid和grid,为什么不使用'$(“#grid_id”)。find('#'+ record);' –
我想你只需要使用parent
财产localData
:localData.parent
。这是父节点的id
。顺便说一下,节点的id
通常会保存在_id_
属性中(因此localData._id_
与rowid
相同,dataOfParentNode._id_
与localData.parent
相同)。为了得到父节点的完整数据,可以使用getLocalRow
代替getNodeParent
:
beforeSelectRow: function (rowid, e) {
var $this = $(this),
localData = $this.jqGrid("getLocalRow", rowid),
dataOfParentNode = $this.jqGrid("getLocalRow", localData.parent);
...
return true;
}
应该警惕(parentNode.attr(“身份证”))或警报(parentNode [0] .ID),因为parentNode是jQuery对象 –
感谢您的回复。 alert(parentNode.attr('id'))或alert(parentNode [0] .id)给出错误“找不到未定义的ID”... alert(parentNode)返回:[object object] –