如何将按钮控件绑定到 cfc 以切换布尔数据库值

发布于 2024-08-08 01:17:01 字数 1035 浏览 4 评论 0原文

我希望能够绑定一系列 3 个按钮来切换数据库消息条目上的 3 个布尔值。布尔数据库条目为已读|未读、已执行|待处理、推荐|消息,并且消息条目具有唯一键“messageID”。我希望按钮显示记录起始值(我认为是bindonload =“true”)。

我已经一瘸一拐地走向

<cfform>
<cfinput type="hidden" name="switchName" value="read"> 
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle@click},{switchName@none})" 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 值以显示初始状态感到困惑。

还有一种方法可以在绑定语句中传递其他变量,而不使用隐藏字段和control@none 格式,例如我需要传递messageID,以便我可以更新正确的记录。如果我知道如何以更好的方式简单地传递 switchName 变量,我就不会放入 switchName 输入。

非常感谢您能提供任何帮助?

I would like to able to bind a series of 3 buttons to toggle 3 boolean values on a database message entry. The boolean database entries are read|unread, actioned|pending, referral|message and the message entry has the unique key "messageID". I want the buttons to display the record starting values (which I presume is bindonload="true").

I've limped towards

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

and in the 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>

This gets me some of the way there, in so far as it toggles the button label, but I'm foxed on how to pick up the initial db values to display the initial status.

Also is there a way to pass other variables in the bind statement without using hidden fields and control@none format, e.g. I will need to pass in the messageID so I can update the correct record. I wouldn't have put in the switchName input if I knew how to simply pass the switchName variable in a beter way.

Many thanks for any light you can shed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莫相离 2024-08-15 01:17:01

怎么样...

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

或者:

<cfajaxproxy bind="javascript:yourJSFunc({toggle@click})">

在你的 JSFunc 中,使用你需要的任何 JS 变量。

How about...

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

or alternatively:

<cfajaxproxy bind="javascript:yourJSFunc({toggle@click})">

and in your yourJSFunc, use whatever JS var's you need.

忆依然 2024-08-15 01:17:01

这对亨利有帮助。

我让它工作了,虽然感觉有点笨拙......

<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1@click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2@click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3@click},'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>

如果有更灵活的方法,请告诉我。

That helped Henry.

I got it working, though it feels a bit kludgy...

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

and the 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>

If there's a slicker way please let me know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文