gpt4 book ai didi

struct - 使用 structFindKey 及其路径通过 Coldfusion 添加新节点

转载 作者:行者123 更新时间:2023-12-02 08:23:15 25 4
gpt4 key购买 nike

我正在尝试使用 structFindKey 从查询创建“org”结构。

我从一个如下所示的查询开始。 enter image description here

从此我试图构建一个代表实际组织结构的结构,我希望它看起来像这样:

enter image description here

我从我的 request.hierarchyStruct 开始,如下所示: enter image description here

这是到目前为止的代码

  for(row in getCorpUserHierarchy){

insertIntoHierachy(row);

}


function insertIntoHierachy(thisRow){
var thisKey = thisRow.parentGroupId;
var newChild = {
"level" = thisRow.ThisLevel
, "levelName" = thisRow.levelName
, "groupName" = thisRow.groupName
, "members" = []
};

keyResult = structFindKey(request.hierarchyStruct, thisKey, "one");
if(arrayLen(keyResult) > 0){
writeDump(keyResult);
newPath = 'request.hierarchyStruct' & keyResult[1].path;
foundKey = structGet(newPath);
foundKey[thisRow.groupId] = newChild;
}
}

我能够“找到转储关键结果的关键”:

enter image description here

但是当第一行“Jasmines Region”找到并尝试将“newChild”添加到其中时,我收到错误 enter image description here

我尝试了多种路径组合,包括

var newPath = keyResult[1].path;    
var fullPath = 'request.hierarchyStruct'
var pathArray = listToArray(newPath,'.');

for(i in pathArray){
fullPath = fullpath & "." & i ;
}

我不知道这是否很重要,但我使用的是最新版本的LUCEE而不是adobe的coldfusion。

这是第一次使用structFindKey,它的路径有人能解释一下吗???

最佳答案

您可能偶然发现了 Lucee 中的一个错误。您的代码似乎适用于 Adob​​e ColdFusion。我创建了一个gist on TryCF showing this

<cfscript>
hierarchyStruct = {};
hierarchyStruct.0 = {
"groupName" = "top level"
, "level" = "1"
, "levelName" = "region"
};
writeDump(hierarchyStruct);

keyResult = structFindKey(hierarchyStruct, "0", "one");
writeDump(keyResult);

newPath = 'hierarchyStruct' & keyResult[1].path;
writeDump(newPath);

foundKey = structGet(newPath);
writeDump(foundKey);
</cfscript>

该要点是使用 Adob​​e ColdFusion 11 并且它将运行。把引擎改成Lucee就会报错。

您可以通过更改 request.hierarchyStruct.0 结构的名称来解决此错误。请注意,该结构在名为 0 时失败。

例如,我创建了another gist changing the name将该结构转换为 a0 并且它可以使用 Lucee 运行。

<cfscript>
hierarchyStruct = {};
hierarchyStruct.a0 = {
"groupName" = "top level"
, "level" = "1"
, "levelName" = "region"
};
writeDump(hierarchyStruct);

keyResult = structFindKey(hierarchyStruct, "a0", "one");
writeDump(keyResult);

newPath = 'hierarchyStruct' & keyResult[1].path;
writeDump(newPath);

foundKey = structGet(newPath);
writeDump(foundKey);
</cfscript>

关于struct - 使用 structFindKey 及其路径通过 Coldfusion 添加新节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42520609/

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