user3454903
user3454903

Reputation:

Checking the structure is existing or not

Here is my array loop which has structures inside that

I am looping over it and i need to skip those fields where the struct is not defined, howver i am getting everytime

Here is my code:

<cfloop index="apos" from=1 to="#arrayLen(myarray)#">
<cfdump var="#myarray[apos].company#">
    <cfdump var="#StructKeyExists(myarray[apos].company,'#myarray[apos].company.size#')#">
    <cfdump var="#StructFindKey(myarray[apos].company,'myarray[apos].company.size','ALL')#">
</cfloop>

The error is throwing on line 3, where i am getting error: Element COMPANY.SIZE is undefined in a CFML structure referenced as part of an expression.

Although i had tried the structFindvalue, but that does not work, perhaps that is expecting some simple values, so what could be the best possible alternative here

Upvotes: 2

Views: 154

Answers (1)

Matt Busche
Matt Busche

Reputation: 14333

With structKeyExists you want to give that function the struture to look and the key you're looking for, so in myarray[apos].company you want to see if 'size' exists, not the entire structure.

<cfloop index="apos" from=1 to="#arrayLen(myarray)#">
  <cfdump var="#myarray[apos].company#">
  <cfdump var="#StructKeyExists(myarray[apos].company,'size')#">
</cfloop>

Upvotes: 3

Related Questions