将ColdFusion输出中的#视为文本而不是变量? [英] Treat a # in ColdFusion output as just text and not a variable?

查看:66
本文介绍了将ColdFusion输出中的#视为文本而不是变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个JQuery列表,我希望从数据库中填写车牌号码,为此,我创建了一个新的cfm文件并让它在html中输出我想要的内容,以便稍后我可以将其转换像这样:

I have made a JQuery list that I want to fill up with license plate numbers from a database, and to do so, I created a new cfm file and had it output what I wanted in html so I could just convert it later like this:

setPlates.cfm

setPlates.cfm

<cfquery name="q_sample" datasource="cars_live">
  SELECT LICENSE FROM veh_rec 
</cfquery>

<cfoutput query="q_sample" >
        <li><a href='#Student'>#license#</a></li>
</cfoutput>

我调用get函数进入setPlates.cfm文件,这样我就可以添加许可证了数据库作为我列表中的项目。代码如下:

I call the get function to go into the setPlates.cfm file so I can add the license plates from the database as items in my list. Code is below:

<div class="ui-grid-solo">
            <div class="ui-block-a"><br></div>
            <div class="ui-block-a"><ul id="plates" data-role="listview" data-inset="true" data-filter="true" data-filter-reveal="true" data-filter-placeholder="Filter Students">
            <script type="text/javascript">
            $.get("setPlates.cfm")
                .done(function(data) {
                  $("#plates").html(data);
                });
                </script>
                <div id="plates"></div>
            </ul></div>
        </div><!-- /grid solo -->

事情是,当它转到那个新文件并开始读取输出时,#Student会混淆它,因为它试图将其作为数据库中的变量读取。 #Student是一个将页面更改为新页面的调用,该页面将根据选择的牌照列出学生信息(例如他们是否拥有停车许可证)。有没有办法让它将英镑符号视为文本,而不是像#certault#?有点像你会在java中使用字符串中的引号吗?

Thing is, when it goes to that new file and starts reading the output, the #Student confuses it, because it's trying to read it as a variable in the database. #Student is a call to change pages to a new page which will list student information (like whether or not they own a parking permit) based on which license plate was selected. Is there a way to make it treat that pound sign as text, as opposed to the start of something like #license#? Kind of like you would do \" to use quotes inside of a string in java?

另外,如果我从学生面前删除#,所有许可证盘子出现在列表中,但他们没有带我到我想要到达的学生页面。

Also, if I remove the # from in front of student, all the license plates show up in the list, but they dont take me to the student page I'm trying to reach.

推荐答案

当你知道,在coldfusion中是一个特殊字符,用于包装变量,以便在cfoutput内部或其他特定内容时输出变量的内容标签,例如cfmail。如果你想在你的文本中使用,你必须通过放置第二个#就在旁边。

As you know, # in coldfusion is a special character that is used to wrap a variable so that it outputs the contents of the variable when you are inside of a cfoutput or inside of other specific tags, such as cfmail. If you want to use # in your text, you must escape it by placing a second # right next to it.

<cfoutput>
    the item## is #itemnumber#
</cfoutput>

当你进入coldfusion标签的属性时,更进一步,您可以使用在coldfusion标记的属性中的字符串中转义

Taking this a step further, when you're inside of a coldfusion tag's attribute, you can use "" to escape " within a string in an attribute of a coldfusion tag.

我在你的情况下,我会这样做:

In your case, i'd do this:

<cfoutput query="q_sample" >
        <li><a href='##Student'>#q_sample.license#</a></li>
</cfoutput>

或者这个:

<cfloop query="q_sample" >
        <li><a href='#Student'><cfoutput>#q_sample.license#</cfoutput></a></li>
</cfloop>

注意,我在变量中添加了 q_sample 名字,因为这是一个很好的做法。

Note, i added q_sample to the variable name because it's a good practice.

这篇关于将ColdFusion输出中的#视为文本而不是变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆