2009-10-13 3 views
0

데이터베이스 메시지 항목에 3 개의 부울 값을 토글하기 위해 일련의 3 개의 버튼을 바인드 할 수 있습니다. 부울 데이터베이스 항목은 읽지 않은 | 읽지 않은 | 보류중인 | referral | 메시지이고 메시지 항목에는 고유 키 "messageID"가 있습니다. 단추가 레코드 시작 값을 표시하도록합니다 (bindonload = "true"라고 가정합니다).버튼 컨트롤을 cfc에 바인드하여 부울 값 데이터베이스를 전환하는 방법

나는

<cfform> 
<cfinput type="hidden" name="switchName" value="read"> 
<cfinput type="button" bind="cfc:cfcs.messages.toggle({[email protected]},{[email protected]})" name="toggleRead" value="Read" bindonload="true"> 
</cfform> 

으로하고, CFC

<cffunction access="remote" name="toggle" output="false" returntype="any" > 
<cfargument required="true" name="toggle" type="any"/> 
<cfargument required="true" name="switchName" type="any"/> 
<cfif toggle eq "Read"> 
     <cfreturn "Unread"> 
<cfelseif toggle eq "Unread"> 
    <cfreturn "Read"> 
</cfif> 
</cffunction> 

이 지금까지이 단추 레이블을 토글로, 길의 일부가 저를 얻는다에 절뚝했지만, 난 초기 상태를 표시하기 위해 초기 db 값을 선택하는 방법에 대해 foxed.

숨겨진 필드를 사용하지 않고 @ none 형식을 사용하지 않고 bind 문에서 다른 변수를 전달하는 방법이 있습니다. 올바른 레코드를 업데이트 할 수 있도록 messageID를 전달해야합니다. 더 간단하게 switchName 변수를 전달하는 방법을 알고 있다면 switchName 입력을 넣지 않았을 것입니다.

빛을 비추어 주셔서 감사합니다.

답변

0

헨리를 도왔습니다.

나는 조금 미봉책 느낌 비록 그것이 ...,

<cfform> 
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{[email protected]},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES"> 
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{[email protected]},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES"> 
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{[email protected]},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES"> 
</cfform> 

와 CFC 알려 주시기 바랍니다 야바위꾼 방법이 있다면

<cfcomponent> 
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record"> 
    <cfargument required="true" name="dsn" type="string"/> 
    <cfargument required="true" name="messageID" type="numeric"/> 
    <cfargument required="true" name="buttonLabel" type="string"/> 
    <cfargument required="true" name="switchName" type="string"/> 
    <cfargument required="true" name="switchOnLabel" type="string"/> 
    <cfargument required="true" name="switchOffLabel" type="string"/> 
    <cfset var returnMessage = "" /> 
    <cfset var temp = "" /> 

    <cfquery datasource='#arguments.dsn#' name="getSwitchData"> 
    SELECT #arguments.switchName# 
    FROM messages 
    WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/> 
    </cfquery> 

    <cfset temp="getswitchdata."&#switchName#> 

    <cfif #Evaluate(temp)# is 1> 
    <cfset returnMessage="#arguments.switchOnLabel#"> 
    <cfelse> 
    <cfset returnMessage="#arguments.switchOffLabel#"> 
    </cfif> 

    <cfif buttonLabel eq ""> 
    <cfreturn returnMessage> 
    <cfelseif buttonLabel eq "#arguments.switchOffLabel#"> 
    <cfquery datasource='#arguments.dsn#'> 
    UPDATE messages 
    SET #arguments.switchName#=1 
    WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/> 
    </cfquery> 
    <cfreturn "#arguments.switchOnLabel#"> 
    <cfelseif buttonLabel eq "#arguments.switchOnLabel#"> 
    <cfquery datasource='#arguments.dsn#'> 
    UPDATE messages 
    SET #arguments.switchName#=0 
    WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/> 
    </cfquery> 
    <cfreturn "#arguments.switchOffLabel#"> 
    </cfif> 
</cffunction> 

작업 얻었다.

1

어떻게 다른 방법

<cfinput type="button" bind="cfc:cfcs.messages.toggle({[email protected]}, #switchName#)" value="#initialValue#" bindonload="false"> 

또는

... 약 : JS VAR의 당신이 필요로하는 무엇이든 사용

<cfajaxproxy bind="javascript:yourJSFunc({[email protected]})"> 

하고 yourJSFunc있다.