- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 CFC 通过 AJAX 执行查询,以获取要在我的页面上显示的图像信息/路径列表。在我的表中,我有一个 bool 列 main
指示图像是否是主图像并因此显示在所有其他图像之上。
由于我通过 AJAX 访问查询结果,因此我需要先创建一个数据数组,然后再将其返回到我的 javascript 函数循环返回的数据并构造 <img>
的页面。标签。
如何让我的 CFC 或 javascript 循环识别 main
bool 值并将该图像移动到第一个位置以显示在我的页面上?
这是我的 CFC:
<cfquery name="project_images">
select path, title, alt, main from tbl_images where pid = #projects.pid#;
</cfquery>
<cfloop query="project_images">
<cfset imgStruct = structNew()>
<cfset imgStruct["path"] = path>
<cfset imgStruct["alt"] = alt>
<cfset imgStruct["title"] = title>
<cfset imgStruct["main"] = main>
<cfset ArrayAppend(imgArray, imgStruct)>
</cfloop>
<cfset local.response["images"] = #imgArray#>
<cfreturn local.response>
还有我的 jQuery 函数:
$('.project_class').click(function(e){
e.preventDefault();
var theclass = $(this).attr('id');
var cat = 'planning';
$.getJSON("../cfc/projects.cfc?returnFormat=json&method=getProjects",
{"theclass":theclass, "cat":cat},
function(response){
$('#portfolio_item').html(response.html);
var imageData = response.images;
$.each(imageData, function(i, item) {
$('#portfolio_item').append('<img src="..' + item.path + '" />');
});
});
});
最佳答案
一个选项是在 SQL 中对图像进行排序。使用 CASE
语句为 main
记录分配比其他记录更高的排序顺序。
SELECT CASE WHEN main = 1 THEN 0 ELSE 1 END AS SortNum
, path
, title
, alt
, main
FROM tbl_images
WHERE pid = <cfqueryparam value="#projects.pid#" cfsqltype="cf_sql_integer">
ORDER BY SortNum
或者您可以检查循环中的 main
标志,并在该标志为 true 时使用 arrayPrepend
而不是 arrayAppend
。
关于jquery - 如果 x=true,则将项目移动到 <cfloop> 中的第一个数组位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9746251/
我希望使用 cfpdfform 将 cfform 中的表单值传递给 PDF。这是我的小测试页,循环遍历 50 条记录以提取名字和姓氏。我正在尝试将它们拉入 pdf 字段。目前它将所有 50 个名字放入
我指的是之前的 SO Coldfusion Calculate Sum Total (Loop? )这被标记为正确答案,但代码对我不起作用。 我正在尝试从多个字段创建一个总计。但是我收到的错误是“ u
我希望使用 cfpdfform 将 cfform 中的表单值传递给 PDF。这是我的小测试页,循环遍历 50 条记录以提取名字和姓氏。我正在尝试将它们拉入 pdf 字段。目前它将所有 50 个名字放入
我有用户参加的测验列表,并列出了正确答案的数量,测验类别,分数和测验ID。 在Coldfusion中,有一个cfloop贯穿每个测验,并即时计算每个测验的平均分数,最高分数,低分数并显示出来。这是永远
我在页面 form.html 上有以下表单,它提交给 cfpage.cfm。名字、姓氏、地址和年龄都显示出来,但顺序不一致。有时它会显示姓氏、名字、地址和年龄。在另一种情况下,它可能会显示地址、名字、
我正在将 ColdFusion 应用程序转换为 C#(我是 CF n00b)。 我有一个脚本执行 cfquery,然后执行 cfloop 的结果,它似乎试图将当前行与其下一行进行比较。它似乎试图确保它
所以我有这段代码: #filesArray[arrayIndex]# #ArraySort(filesArray
我对这种冷融合语言还很陌生,我做了一些教程,我只是按照类(class)告诉我的去做,但是我在这段代码上遇到了错误,有人可以向我解释为什么吗? #
我有两张 table 。第一个用于类别,第二个用于问题。 category table: category_id category_name questions table: questio
我的 MySQL 项目数据库中有一些记录,这些记录有几个 bool 标志来帮助我对数据进行排序。我有 3 个类别 planning , landscape , 和 environmental每个类别有
背景/目的:我正在创建一个 Coldfusion 文档,其中包含用于从公司数据库中获取值的 SQL。我正在查找我们团队中每个销售代表的转化率(已售许可证/注册数)。每个销售代表都有一个与用户关联的 I
第一次发帖。我正在使用 从 Excel 创建查询,然后尝试将查询结果插入 MySQL 表。那工作正常。我还需要从一列中获取一个值并将其正确的 ID 号插入到表中的 ID 列中。这是我的代码。我得到的结
下午好。目前我正在从查询中格式化一些 json,当我到达循环查询的地步时,我发现了一个非常奇怪的现象。我将 startrow 指定为 20,将 endrow 指定为 40。运行时,我在填充 20-40
我经常对数组或列表使用 cfloop,因为我有涉及数组值的复杂计算。但是,似乎没有办法返回到数组/列表的特定成员。如果我使用普通循环,我可以很容易地做到这一点: ... do somethi
我正在使用 cfloop 创建一个新数组并且出于某种原因,ColdFusion 为 MyNewArray 中的每个值在页面 HTML 中注入(inject)了单词“YES”。 .因此,通过下面的代码,
我在 ColdFusion 中有一个网页,它显示了 SQL 表中的内容。内容使用 cfloop 进行迭代,并使用 div block 呈现。我的代码片段如下- Date:#qry1.dat
我在 cfloop 里面通过查询。我想获得一个属性,但直到运行时我才知道该属性是什么。使用 #qryResult[MyAttr]#失败并出现错误“无法将复杂对象类型转换为简单值”。这样做的语法是什么?
我正在尝试使用 cfloop 从 0.0 循环到 5.0,但它去掉了小数点,而是从 0 循环到 5。 这是我的代码 --- #cweight# 我需要循
我有一个将查询输出到 jQuery 可排序列表。所有可排序标签( , 等)都包含在循环内。我需要锚定第一个 使用 CSS 将元素添加到页面上的设定区域。但我不想在第一次迭代后应用此 CSS。
今晚的最后一个问题,仍然使用 Coldfusion8 和 MySQL。 我有一个包含产品的表,每个产品都有价格 A、B 和 C。我需要检索所有价格中 A、B、C 的最小值和最大值(A_min、A_ma
我是一名优秀的程序员,十分优秀!