Highlighted

Pulling Out Struct Variables

New Here ,
Jun 18, 2019

Copy link to clipboard

Copied

Newbie question here… how do I get / set these values in this (sub)Struct to variables?

struct.gif

In the end, I want to have them set to variables like:

<cfset CategoryID = StructVar>
<cfset CategoryName = StructVar>

Thanks!

Views

102

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Pulling Out Struct Variables

New Here ,
Jun 18, 2019

Copy link to clipboard

Copied

Newbie question here… how do I get / set these values in this (sub)Struct to variables?

struct.gif

In the end, I want to have them set to variables like:

<cfset CategoryID = StructVar>
<cfset CategoryName = StructVar>

Thanks!

Views

103

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 18, 2019 0
New Here ,
Jun 19, 2019

Copy link to clipboard

Copied

Actually ended up figuring this one out.

I used:

<cfset CategoryID =i.category.id>
<cfset CategoryName =i.category.name>

Since my CFLOOP over this array is:

<cfloop array="#deserialized#" index=“i”>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2019 0
LEGEND ,
Jun 19, 2019

Copy link to clipboard

Copied

I was going to say that it depends upon what you named the struct, but you did, indeed, figure it out.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2019 0
BKBK LATEST
Adobe Community Professional ,
Jun 19, 2019

Copy link to clipboard

Copied

MrLeG8  wrote

Actually ended up figuring this one out.

<cfset CategoryID =i.category.id>
<cfset CategoryName =i.category.name>

This is correct, but has the disadvantage that you overwrite the values of categoryID and categoryName at every iteration of the loop. If you wanted a more reusable solution, you could do something like

<cfset categoryID=arrayNew(1)>

<cfset categoryName=arrayNew(1)>

<cfloop from="1" to="#arrayLen(deserialized)#" index="n">

    <cfset categoryID=deserialized["category"]["id"]>

    <cfset categoryName=deserialized["category"]["name"]>

</cfloop>

<!--- verify --->

<cfdump var="#categoryID#" >

<cfdump var="#categoryName#" >

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2019 0