如何将按钮控件绑定到 cfc 以切换布尔数据库值
我希望能够绑定一系列 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样...
或者:
在你的 JSFunc 中,使用你需要的任何 JS 变量。
How about...
or alternatively:
and in your yourJSFunc, use whatever JS var's you need.
这对亨利有帮助。
我让它工作了,虽然感觉有点笨拙......
还有 cfc
如果有更灵活的方法,请告诉我。
That helped Henry.
I got it working, though it feels a bit kludgy...
and the cfc
If there's a slicker way please let me know.