How do I parse this structure? I need to turn this into single variables. E.g. from the attributes struct:
name
type
value
I'm not familiar with structures, and I need to e开发者_C百科nter this type of data into a database.
I've played around with cfloop
, but nothing.
Assuming your variable name is "foo", you can access the name like this
foo.attributes.name
Structures are simply accessed via dot notation.
If you want to simply dump this structure, use a simple XML and store it in a CLOB or BLOB field. But if you want to perform operations such as search, frequent changes to the data, then its better you consider tree structures.
If you are using Oracle, take a look at CONNECT BY PRIOR, this makes you store values in the database directly as rows and later query them and load into a tree structure.
The gist here is you should both be able to store and retrieve data as if you are dealing with a simple TREE data structure.
Along the same lines as what Ben said, I'm not sure why you'd want to pull this nice little struct apart. Use it in its current form by accessing the values inside it rather than disassembling it.
<cfloop collection="#foo.attributes#" item="myKey">
<cfoutput>Value of #myKey# is #structFind(foo.attributes, myKey)#</cfoutput>
</cfloop>
Refer to the LiveDocs' structure looping page for more details.
精彩评论