【发布时间】:2017-05-09 02:42:11
【问题描述】:
首先,我找到了这个解决方案 (ColdFusion - Displaying rows as columns),如果我可以使用 table,它将解决我的问题,但我不能,因为这需要响应。但是,客户不喜欢响应式表格。他们真的,真的更喜欢显示列,这样用户只需要上下滚动,而不是上下左右滚动边。
我需要一些帮助将表格转换为引导程序<div>'s。我知道基础知识:跳过表格,tr 等于 div class="row" 和 td 等于 div class="col-sm-*" 的东西。但是,更具体地说,我不确定用于转换上述 SO 解决方案的逻辑以及如何将其应用于我的需求。
将 Lucee 与 Bootstrap v3 一起使用,我正在尝试填充“网格”,但我需要在填充 column2 之前填充 column1 中的行。
1|10|20|30|40
2|11|21|31|41
3|12|22|32|42
4|13|23|33|43
下面的代码 sn-p 来自 @travis,我不相信它
<cfset cols = 5>
<!--- get the number of rows so you know what record to display at the top of the next row. for example if our query contains "a,b,c,d,e,f,g,h,i,j,k,l,m" (13 elements) it will produce 3 totalrows--->
<cfset totalRows = ceiling(qMyQuery.RecordCount / cols)>
<!--- set inital record to 1 "output" is the actual cell of the query --->
<cfset output = 1>
<!--- Create table --->
<table width = "100%" border="0" align="center" cellpadding="2" cellspacing = "2">
<!--- loop through the rows. This loop will run 3 times in this example --->
<cfloop from = "1" to = "#totalRows#" index = "thisRow">
<tr>
<!--- this loop will run 5 times in times in this example --->
<cfloop from = "1" to = "#cols#" index = "thisCol">
<!--- the width in the table cell will dynamicaly calculated to evenly distribute the cells. in this example if cols = 5 100/5 will make the cells 20% of the table --->
<td width = "<cfoutput>#numberformat((100/cols), 99)#</cfoutput>%" align="center" nowrap style = "border: 1px solid #ccc;">
<!--- Check current record with the record count, this will be used to display data or an empty cell --->
<cfif output lte qMyQuery.recordCount>
<cfoutput>#qMyQuery.Mon[output]#</cfoutput>
<cfelse>
<!--- use <br> to display an empty cell --->
<br>
</cfif>
<!--- increment counter to the next record in this example if we started on the first cell of the first row it would be 1(a), then 4(d), then 7(g) and so on if this was the firs cell on the second row it would be 2(b), 5(e), 8(h), continue... --->
<cfset output = output + totalRows>
</td>
</cfloop>
<!--- this little bit tells where to start the next row. if we just finished the first row output would be 2(b) --->
<cfset output = thisRow + 1>
</tr>
</cfloop>
</table>
这是我尝试使用引导程序完成同样的事情:
<!-- what I'm working with -->
<cfset cols = 2>
<!-- get the number of rows so you know what record to display at the top of the next row. for example if our query contains "a,b,c,d,e,f,g,h,i,j,k,l,m" (13 elements) it will produce 3 totalrows-->
<cfset totalRows = ceiling(qMyQuery.RecordCount / cols)>
<!--- set inital record to 1 "output" is the actual cell of the query --->
<cfset output = 1>
<!--- Create table --->
<div class="row">
<div class="col-sm-12">
<!--- loop through the rows. This loop will run 3 times in this example --->
<cfloop from = "1" to = "#totalRows#" index = "thisRow">
<div class="row">
<!--- this loop will run 5 times in this example --->
<cfloop from = "1" to = "#cols#" index = "thisCol">
<div class="col-xs-3" style="border:1px solid red">
<cfif output lte qMyQuery.recordCount>
<cfoutput>#qMyQuery.mon[output]#</cfoutput>
<cfelse>
<br>
</cfif>
<cfset output = output + totalRows>
</div>
</cfloop>
<cfset output = thisRow + 1>
</div>
</cfloop>
</div>
</div>
但是,我的工作输出只是在一个全宽页面中显示所有内容(border:1px 纯红色的内联样式用于查看代码生成的内容)。虽然这是针对 ColdFusion,但我认为循环的逻辑与 PHP 相同。
对此有任何提示、技巧、建议或最好的解决方案吗?
【问题讨论】:
-
Bootstrap 3.x 的网格系统使用 12 为基数。如果上面代码中的注释是正确的; “循环将运行 5 次”,这将创建五个 col-sx-3 div,总计 15 个。另一个潜在问题是 col-sx-3(在循环中)可能是一个错字。标准网格类是 col-xs-、col-sm-、cols-md- 和 col-lg-。当然,col-sx-3 可以是用户自定义的类...
-
所以在我修复了一些缩进和其他东西之前不会让我发布我的代码,我忘记了它是什么。我熟悉网格(喜欢它)。 sx 是一个错字,我会在代码中修正它。至于列数,当前设置为 2 需要根据用于查看页面的设备是动态的。我将其留在代码中以帮助解释变量和值的位置,但事后认为它可能反而增加了混乱。
-
我想过做一些快速的数学计算来获得返回的记录数(应该远低于 100)并将其除以我需要的列数,然后执行查询查询,针对每一列数据。
-
我不喜欢
<div class="row">然后<div class="col-sm-12">然后<div class="row">行模式。 Bootstrap 真的不能那样工作。 -
@JamesAMohler 你确定吗? getbootstrap.com/css/#grid-nesting 提供了一个嵌套示例 - 或者这不是您的意思?如果没有,请您详细说明一下吗?
标签: twitter-bootstrap twitter-bootstrap-3 coldfusion lucee