diff --git a/pages/category/category.js b/pages/category/category.js index 802fc6c..d8eaf98 100644 --- a/pages/category/category.js +++ b/pages/category/category.js @@ -32,13 +32,15 @@ Page({ bindTapProduct: function(e) { var that = this var cartItems = wx.getStorageSync('cartItems') || [] - var thisItem = this.data.items.find(function(ele){ + var thisItem = this.data.items.filter(function(ele){ return ele.id === e.currentTarget.dataset.id - }) + })[0] - var exist = cartItems.find(function(ele){ - return ele.id === thisItem.id - }) + if (thisItem) { + var exist = cartItems.filter(function(ele){ + return ele.id === thisItem.id + })[0] + } if (exist) { exist.quantity = parseInt(exist.quantity) + 1 diff --git a/pages/show_product/show_product.js b/pages/show_product/show_product.js index 34dd5c2..e99561a 100644 --- a/pages/show_product/show_product.js +++ b/pages/show_product/show_product.js @@ -11,7 +11,7 @@ Page({ onLoad (params) { var allProducts = wx.getStorageSync('products') var id = params.id - var product = wx.getStorageSync('products').filter(function(i){ + var product = allProducts.filter(function(i){ return i.id === id })[0]