'更新购物车
sub UpdateCart(key,value)
    cart.item(key)
=value
end sub


'从购物车中减掉
sub RemoveItemFromCart(key)
    
if cart.exists(key) then
        response.write cart.exists(key)
        cart.remove(key)
    
end if
end sub

'批量移除
sub BatchRemoveCart(keyString)
    
dim keys,itemkey,i,m
    keys
=split(keyString,",")
    m
=ubound(keys)
    
for i=0 to m
        RemoveItemFromCart keys(i)
    
next
end sub

'输出
sub OutputCart()
    
for each key in cart.keys
        response.write key
&"="&cart.item(key)&typename(key)&"<br>"
    
next
end sub

'清空
sub ClearCart()
    cart.removeall
end sub

'由分隔的key/value字符串更新购物车
sub BatchUpdateCart(keyString,valueString)
    
dim keys,values,itemkey,i,n,t
    keys
=split(keyString,",")
    values
=split(valueString,",")    
    m
=ubound(keys)    
    n
=ubound(values)
    
for i=0 to m
        
if i>then t=1 else t=values(i)
        UpdateCart keys(i),t
    
next
end sub

'由dictionary转换为字符串
function GetKeyString()
    
dim keys
    keys
=""
    
if cart.count>0 then    
    
for each key in cart.keys
        keys
=keys&key&","
    
next
    keys
=mid(keys,1,len(keys)-1)
    
end if
    GetKeyString
=keys
end function

'取其中一个值
function GetCartItem(key)
    t
=cart.item(key)
    GetCartItem
=t
end function

以上是我在做的一个项目中购物车的实现,其中cart是一个定义在global.asa中的session scope变量,类型为:dictionary
但就是这个dictionary,把我搞晕了
主要是在处理购物车中产品移除时
productidlist=request("ProductIdList").item
得到CHECKBOX 的值,形式是一个逗号分隔的产品ID列表
然后我调用了BatchRemoveCart productidlist
BatchRemoveCart 又调用removecartitem(key)来进行移除操作
但问题就出在这,通过输出,我发现,在实际移除时,发现两个怪事:
1,无规律的某些项目没法移出,不会产生任何错误
2,removecartitem中,判断了项目是否存在,如果存在,则移除,并且,输出判断表达式的值,但我发现,每次VBS判断的isexists的值是false,但它却莫名其妙的执行了remove操作.实在令人费解