1
我有一个简单的“购物车”,由用户更新询价。他们阵列工作正常,附加效果很好。但由于某种原因,我似乎无法正确输出数据到表格中。我的循环计数器正在工作,如果这是重要的:)请参阅下面的代码,然后输出我试图去工作我知道这很简单,我在想它。CF阵列的输出
感谢
<cfif isDefined("url.Series")>
<cfset arrayAppend(session.cart, {Series = URL.Series , Style = URL.Style , Ohm = URL.Ohm , Notes = URL.Notes})>
</cfif>
<a href="cleararray.cfm">Clear Array</a><br />
<a href="Stylesearch.cfm">Style Search</a><br /><br />
<h1><b>DEBUG:</b></h1>
<!--- Display current contents of cart --->
<cfdump var="#session.cart#" label="Cart Items">
<br />
<!--- Display items in cart in Table format --->
<table class="tftable" border="1">
<tr>
<th>Series</th>
<th>Style ID</th>
<th>Exact Ω</th>
<th>Description</th>
<th>Notes</th>
<th>Quantity</th>
<th>Update</th>
<th>Delete</th>
</tr>
<cfloop index="Series" from="1" to="#arraylen(session.cart)#">
<tr>
<td>#session.cart[Series]#</td>
<td>#Style#</td>
<td>#Ohm#</td>
<td>Test Description</td>
<td>#Notes#</td>
<td>Test Quantity</td>
<td>X</td>
<td>^</td>
</tr>
</cfloop>
</table>
Phipps,感谢这工作得很好,我有一点后续问题,一个例子可能会帮助我节省数小时。我将为每一行编写更新函数,我将如何去做这件事,因为他们需要解决阵列的适当行。这就是表中的最后两个字段(更新/删除)。提前致谢。 –
有很多方法可以做到这一点。您最好创建一个cart.cfc来处理项目的添加/更新/删除。像这样:[简单购物车](https://www.bennadel.com/blog/637-ask-ben-creating-a-simple-wish-list-shopping-cart.htm)这有点旧,但是原则在那里。然后,您需要决定是否要为每次更新返回服务器(并重新加载整个页面),或者使用异步JavaScript请求在后台发布数据并在没有页面重新加载的情况下更新购物车。 – Phipps73
注意,如果你不需要任何索引号,你也可以使用'array'循环(而不是'from/to'),所以'index'变成当前数组元素,而不是位置。 – Leigh