在 ColdFusion 中通过 URL 传递后,如何保留在下拉菜单中所做的选择?
我的 ColdFusion 页面上有一个下拉菜单,可以根据选择过滤数据列表。通过 URL 传递选择并显示结果。问题是我想保留页面重新加载后所做的选择。现在每次都会回到第一个选项。
这是我通过下拉菜单的 onChange 来通过 URL 传递它的方法:
<cfif IsDefined(url.filterBy)>
query...
</cfif>
I have a drop down menu on my ColdFusion page that filters a list of data based on its selection. The selection is passed through the URL and the results are displayed. The problem is that I would like to keep the selection that was made after the page has reloaded. Right now it goes back to the first option every time.
This is how I pass it through the URL by the onChange of the drop down menu:
<cfif IsDefined(url.filterBy)>
query...
</cfif>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在选项标记内,放置一个 if 语句来检查通过表单范围传递的值。
所以:
Inside your option tag, you place an if statement that checks the value passed via the form scope.
So:
如果我正确地阅读了您的问题,您只需查看现有的
URL.filterby
值是否与您的 SELECT 中的值匹配。CFPARAM 确保 URL.filterby 始终有一个值。
selectIf
只是一个 UDF,我用它来防止 CFML 代码弄乱我的 HTML。它只接受任何可以解释为布尔值的内容并返回适当的字符串。然后页面的其余部分可以查看 URL.filterby,如果它有值,则执行查询并显示数据。
If I'm reading your question right, you just need to see if the existing
URL.filterby
value matches a value in your SELECT.The CFPARAM ensures that there's always a value for URL.filterby.
selectIf
is just a UDF that I use to keep from cluttering my HTML with CFML code. It simply takes anything that can be interpreted as a boolean and returns a string as appropriate.Then the rest of your page can look at URL.filterby and if it has a value, then do your query and display your data.
所以,我想出了一种不同的方式(某种程度上)。我所做的就是抓取 URL 的字符串查询部分,仅修剪国家/地区名称并将其与下拉菜单的值进行比较。
在大多数情况下,效果很好。当涉及到包含多个单词的国家/地区名称时,空格会将其搞乱并且无法保留选择。我也尝试替换空格:
但是,没有好处。有人有解决方案来识别空间吗?
So, I've figured it out a different way (sort of). What I do is grab the String Query part of the URL, trim just the Country Name and compare it the values of the drop down menu.
Works good, for the most part. When it comes down to country names with more than one word, the spaces mess it up and it doesn't keep the selection. I tried also replacing the spaces as such:
But, no good. Anybody have a solution for this to recognize the spaces?