動作検証
FileMaker Pro 19.5.4
カスタム関数
カスタム関数:GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
While (
[
~json = json;
~listKey = JSONListKeys ( ~json ; "" );
~count = ValueCount ( ~listKey ) ;
~data = "";
~n = 1
] ;
~n ≤ ~count ;
[
~data = List(~data ;
Let(
~children = JSONGetElement ( ~json ; "[" & ~n-1 & "]." & childrenKey )
;
If ( ~children ;
List( If( boolParent ; JSONGetElement ( ~json ; "[" & ~n-1 & "]." & target) ) ; GetListFromTreeJson( ~children ; boolParent ; target ; childrenKey )) ;
JSONGetElement ( ~json ; "[" & ~n-1 & "]." & target) )
)
);
~n = ~n + 1
] ;
~data
)
階層構造JSON
階層構造JSON
[
{
"label": "000.txt",
"path": "D:\\000\\000.txt"
},
{
"label": "001",
"path": "D:\\000\\001",
"children": [
{
"label": "001.txt",
"path": "D:\\000\\001\\001.txt"
},
{
"label": "002",
"path": "D:\\000\\001\\002",
"children": [
{
"label": "002-1.txt",
"path": "D:\\000\\001\\002\\002-1.txt"
},
{
"label": "002-2.txt",
"path": "D:\\000\\001\\002\\002-2.txt"
},
{
"label": "002.txt",
"path": "D:\\000\\001\\002\\002.txt"
},
{
"label": "003",
"path": "D:\\000\\001\\002\\003",
"children": [
{
"label": "003.txt",
"path": "D:\\000\\001\\002\\003\\003.txt"
}
]
}
]
}
]
},
{
"label": "001-1",
"path": "D:\\000\\001-1",
"children": [
{
"label": "001-1.txt",
"path": "D:\\000\\001-1\\001-1.txt"
}
]
}
]
使用方法
例1
式
Let([
json = FileExplorer::treeData
;boolParent = 0
;target = "path"
;childrenKey = "children"
];
GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
)
結果
D:\000\000.txt
D:\000\001\001.txt
D:\000\001\002\002-1.txt
D:\000\001\002\002-2.txt
D:\000\001\002\002.txt
D:\000\001\002\003\003.txt
D:\000\001-1\001-1.txt
例2
式
Let([
json = FileExplorer::treeData
;boolParent = 0
;target = "label"
;childrenKey = "children"
];
GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
)
結果
000.txt
001.txt
002-1.txt
002-2.txt
002.txt
003.txt
001-1.txt
例3
親も取得
式
Let([
json = FileExplorer::treeData
;boolParent = 1
;target = "path"
;childrenKey = "children"
];
GetListFromTreeJson ( json ; boolParent ; target ; childrenKey )
)
結果
D:\000\000.txt
D:\000\001
D:\000\001\001.txt
D:\000\001\002
D:\000\001\002\002-1.txt
D:\000\001\002\002-2.txt
D:\000\001\002\002.txt
D:\000\001\002\003
D:\000\001\002\003\003.txt
D:\000\001-1
D:\000\001-1\001-1.txt
原创声明:本文系作者授权爱码网发表,未经许可,不得转载;
原文地址:https://www.likecs.com/show-308628014.html