From fb252e1284f486e864fca5e08caeabfd4a236d22 Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Tue, 15 Nov 2016 18:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/category/category.js | 12 +++++++----- pages/show_product/show_product.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) 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]