Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Pulling Out Struct Variables

New Here ,
Jun 18, 2019 Jun 18, 2019

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!

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

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”>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 19, 2019 Jun 19, 2019

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

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2019 Jun 19, 2019
LATEST

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#" >

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