2009-06-25 6 views
4

私は2次元の配列を持っています。私は3つの値を初期化中に配列に書き、配列の値がフォームを渡した値と等しくない場合は4番目の値を追加します。次に、4番目の値が存在するかどうかをチェックします。ColdFusion:特定の要素が2次元配列に存在するかどうかをチェックする方法は?

update.cfm

<cfset array = obj.getArray() /> 
<cfif not StructIsEmpty(form)> 
    <cfloop collection="#form#" item="key"> 
    <cfif left(key,3) eq "ID_"> 
     <cfset number = listLast(key,"_") /> 
     <cfset value = evaluate(0,key) /> 
     <cfloop index="j" from="1" to="#arrayLen(array)#"> 
     <cfif (array[j][1] eq number) and (array[j][3] neq value)> 
      <cfset array[j][3] = value /> 
      <cfset array[j][4] = "true" /> 
     </cfif> 
     </cfloop> 
    </cfif> 
    </cfloop> 
<cfset obj = createObject("component", "cfc.Obj").init(arg = form.arg, argarray = array) /> 
<cfset application.objDao.update(obj) /> 

objDao.cfc更新方法

<cfset matarray = arguments.obj.getArray() /> 
    <cfloop index="i" from="1" to="#arrayLen(array)#"> 
    <cfquery name="qUpdateAsset" datasource="#variables.instance.dsn#"> 
     UPDATE table 
     SET value = <cfqueryparam value="#matarray[i][3]#" cfsqltype="cf_sql_integer" /> 

    <!--- This is wrong, how do i check the existence correctly? ---> 
    <cfif StructKeyExists(matarray[i],"4")> 
     ,status = 'true' 
    </cfif> 

     WHERE arg = <cfqueryparam value="#arguments.obj.getArg()#" cfsqltype="cf_sql_smallint" /> 
     AND number = <cfqueryparam value="#matarray[i][1]#" cfsqltype="cf_sql_integer" /> 
    </cfquery> 
</cfloop> 

このエラーで私の誤った試みの結果:初心者のためのまあ

You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.

答えて

8

のようなものを試してみました:

<cfif ArrayLen(matarray[i]) gte 4> 
     ,status = 'true' 
</cfif> 
+0

であります – mrt181

-3

が、私はありません巨大なCold Fusionの男ですが、構造体ではないので、ArrayKeyExistsをArrayで使用することはできません。また

、あなたは私はあなたがちょうどそうのような配列の長さをチェックする必要があると考えてい

<cfset testValue = matarray[i][4]> 
<cfif isDefined testValue> 
    ... 
</cfif> 
+0

あなたはコースの右に、トリックをした愚かな私 – mrt181