首先,正如您可以通过我的代码所说的那样,我不是程序员,也不知道 javascript。我实际上正在使用 VMware Orchestrator(我相信它基于 Rhino javascript 引擎)来创建一些工作流。请详细解释任何答案。
我正在尝试创建一个将在 vCenter 中创建目录树的工作流。
概念:基本上我试图为调用全局树的树的每一层运行嵌套的 for 循环。
问题:第一个 for 循环工作并创建文件夹“Dev”。第二个 for 循环不起作用并出现错误消息:
[2013-06-27 19:16:16.219] [I] Building folder Dev
[2013-06-27 19:16:16.474] [I] Built directory: Dev
[2013-06-27 19:16:16.476] [I] Building folder Servers
[2013-06-27 19:16:16.480] [I] TypeError: Cannot find function createFolder in object Dev. (Workflow:TEST_TNG_New_Site_Folder_Structure / Scriptable task (item2)#36)
我认为这与 JavaScript 无法将全局函数调用到嵌套对象中有关(我不是程序员,也不知道 JavaScript,所以不要在这方面开枪)
代码:(一旦我开始工作就会清理它)
var folderBase = ["Dev","DMZ","Prod","UAT"];
var folderT1 = ["Servers","Workstations"];
var folderT2 = ["Windows","Linux"];
var folderT3 = ["Repo1","Repo2","Repo3","Repo4"];
var folderT4 = ["T1","T2","T3"];
// Create the folderBase level of folders
for (var i=0,l=folderBase.length; i<l; i++) {
var rootFolder = parentFolder;
buildFolderTree(folderBase[i]);
// Create the folderT1 level of folders
for (var j=0, l=folderT1.length; j<l; j++) {
var rootFolder = folderBase[i];
buildFolderTree(folderT1[j]);
// Create the folderT2 level of folders
for (var k=0, l=folderT2.length; k<l; k++) {
var rootFolder = folderT1[j];
buildFolderTree(folderT2[k]);
// Create the folderT3 level of folders
for (var x=0, l=folderT3.length; x<l; x++) {
var rootFolder = folderT2[k];
buildFolderTree(folderT3[x]);
// Create the folderT4 level of folders
for (var y=0, l=folderT4.length; y<l; y++) {
var rootFolder = folderT3[x];
buildFolderTree(folderT4[y]);
}
}
}
}
}
function buildFolderTree(folderName) {
System.log("Building folder " + folderName);
rootFolder.createFolder(folderName);
System.log("Built directory: " + folderName);
}