[英]Minicart.js - Items are added to cart but cart not displaying
I have a click function on a button that adds an item to my cart using the Minicart.js library from minicartjs.com. 我在按钮上具有单击功能,可以使用minicartjs.com的Minicart.js库将商品添加到购物车中。 When the button is clicked items are being added to the cart however, the cart is not popping up as expected.
但是,单击按钮时,正在将商品添加到购物车中,但购物车并未如预期那样弹出。 I've tested this on up to date versions of Chrome and IE (ie 11).
我已经在最新版本的Chrome和IE(即11)上对此进行了测试。
Some things I've noticed: 我注意到的一些事情:
paypal.minicart.view.show()
the cart displays fine. paypal.minicart.view.show()
则购物车会正常显示。 Even with the items I've added. The following script is at the end of a MVC partial View: 以下脚本位于MVC部分视图的末尾:
<script src="~/Scripts/minicart.js"></script>
<script>
$(".showcart").click(function () {
var data = $(this).attr("data-id");
paypal.minicart.cart.add(JSON.parse(data));
// $("#body").toggleClass("minicart-showing"); <---doesn't work
// paypal.minicart.view.show() <---- doesn't work
});
paypal.minicart.render();
</script>
After further reviewing the minicartjs examples in the author's repository. 在进一步查看作者存储库中的minicartjs示例之后。 I found that using
e.stopPropagation()
within the click function resolves the issue. 我发现在click函数中使用
e.stopPropagation()
可以解决此问题。
$(".showcart").click(function (e) { // <--- added the e function
var data = $(this).attr("data-id");
e.stopPropagation(); // <--- And this line.
paypal.minicart.cart.add(JSON.parse(data));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.