我正在将 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>
此代码在此页面上有效,但是当我浏览到另一个页面时,运输属性似乎已丢失。我基本上会检查每个页面是否已设置送货,如果没有,我会显示设置送货地址的链接。
如何“永久”扩展对象?
最佳答案
只需将 simpleCart 扩展程序添加到实际的 simpleCart.js 文件中即可。
关于javascript - SimpleCart.js - 将运输信息添加到对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25435998/