2012-05-24 3 views
0

내가중첩 된 구조 만들기, 더 좋은 방법은 무엇입니까?

<cffunction name="setDataAllWithFilter" output="false" access="public"> 

    <cfargument name="stCollection" required="true" type="Struct" /> 

    <cfif NOT StructKeyExists(Session, this.LOCAL) > 
     <cfset Session[this.LOCAL] = StructNew() /> 
    </cfif> 

    <cfif NOT StructKeyExists(Session[this.LOCAL], "Data") > 
     <cfset Session[this.LOCAL]["Data"] = StructNew() /> 
    </cfif> 

    <cfif NOT StructKeyExists(Session[this.LOCAL]["Data"], "Filtered") > 
     <cfset Session[this.LOCAL]["Data"]["Filtered"] = StructNew() /> 
    </cfif> 

    <cfreturn SetAll(Arguments.stCollection, Session[this.LOCAL]["Data"]["Filtered"]) /> 

</cffunction> 

같은 중첩 된 구조체 뭔가를 만들려고하고 그것은 이런 OK인가? 아니면 그렇게 할 수있는 더 좋은 방법이 있습니까?

감사

+0

여기서 무엇을 하려는지 확실하지 않습니다. 왜 세션에서 그런 구조체를 생성해야합니까? – Henry

+0

응답 해 주셔서 감사합니다. 사용할 수없는 경우 중첩 된 구조체를 만드는 것이 더 나은 방법일까요? 세션, 요청 또는 기타 LOCAL 구조가 될 수 있습니다. 제가 묻기를 원하는 것은 중첩 된 구조를 만드는 더 좋은 방법이 있습니까? 감사합니다 – user160820

+0

당신은 struct 내에서 구조체로 많은 키를 가진 구조체를 돌리고 있습니까? – Henry

답변

0

현재하고 계시는 것이 좋습니다. cfparam을 사용하여 일상 생활을 쉽게 할 수 있습니다.

<cffunction name="setDataAllWithFilter" output="false" access="public"> 

    <cfargument name="stCollection" required="true" type="Struct" /> 

    <cfparam name="session[this.local]" default="#structNew()#"> 
    <cfparam name="session[this.local].Data" default="#structNew()#"> 
    <cfparam name="session[this.local].Data.Filtered" default="#structNew()#"> 

    <cfreturn SetAll(Arguments.stCollection, Session[this.LOCAL]["Data"]["Filtered"]) /> 

</cffunction> 
1
당신은 당신의 세션 구조를 설정하는 StructAppend()를 사용하여 볼 수 있었다

: 여기이를 테스트하기 위해 아직 시간이 없었습니다하지

<cfscript> 
initStruct = {Data={Filtered={}}}; 
StructAppend(session[this.local],initStruct,false); 
</cfscript> 

을, 그래서 YMMV

1

은 SetVariable 함수는 요구 사항을 충족시키기 위해 중첩 구조를 만듭니다.

<cfset SetVariable("test1.test2.test3",4)> 

은 test1 변수 4.

은 또한 당신이 경로 (문자열)를 기반으로 빈 구조체를 만들 수있는 StructGet 들여다 같다 [ "TEST2"] [ "테스트 3을"] 생성합니다.

+3

당신은 그것을 위해서'setVariable()'을 사용할 필요조차 없습니다. 그냥 사라져서 구조체가 생성 될 것입니다. – Henry

관련 문제