我正在将 SimpleCart.js ( http://simplecartjs.org/ ) 集成到一个小项目中。我想看看是否可以将运输信息实际添加到 SimpleCart 对象中。
我从现有用户帐户中获取运输信息,其中包含:
shipId、ship_first、ship_last、ship_street、ship_city、ship_state、ship_zip、ship_phone
我在文档中看到我可以扩展 SimpleCart.js 对象(http://simplecartjs.org/documentation/simplecart-extend)。所以目前我正在这样做:
在我的 HTML 标记中:
<a href="#" onclick="setShipping(<?php echo $address['id'] . ", '" . $address['ship_first'] [...] ?>Set Address</a>
我的 javascript 看起来像这样:
<script>
function setShipping(shipId, ship_first [...]) {
var shippingInfo = {
shipId: shipId,
ship_first: ship_first,
[...]
};
simpleCart.extend(simpleCart, shippingInfo);
// do some more stuff like updating the checkout button and tax rate
}
</script>
此代码在此页面上有效,但是当我浏览到另一个页面时,运输属性似乎丢失了。我基本上会在每个页面上检查是否设置了送货,如果没有,我会显示设置送货地址的链接。
我将如何“永久”扩展对象?