Hi all
the function:
StructGet( path )
get the value in struct using the path by dot:
a = {
b = {
c = 1
}
}
StuctGet("a.b.c") //return "1"
Works like a charm.
For this, I expect the struct.get( path ) function to work similarly.
Work with (first level struct):
a.get ( "b" ) //return a struct
but not works with a path:
a.get ( "b.c" ) //get an error
key [b.c] doesn't exist
This is a bug?
OS: Windows 10
Lucee Version: 5.3.9.141
Unlikely. “b.c” could be the name of a key.
<cfscript>
a = {
b = {
c = 1
},
"b.c" = 2
}
Writeoutput(a.get("b.c")) // 2
</cfscript>
Struct.get() is not a member function in lucee. It works by invoking the get() method from the struct java class.
Ah, yes, forgot about that (get is using java)!
Part of Map IIRC.
One similar use that I find interesting is getOrDefault:
<cfscript>
a = {
b = {
c = 1
},
"b.c" = 2
}
Writeoutput(a.get("b.c")) // 2
Writeoutput(a.getOrDefault("c.d",3)) //3
</cfscript>
Ah, ok.
Seems a bit inconsistent…
Be aware, the getOrDefault doesn’t set it … It’s weird like that. Might be useful in an edge case though.