Mall development project, now need to make apps, helpless to play before Android but not very proficient. Finally, choose PhoneGap to implement the app.
Because before the shopping cart is divided into landing and landing after two cases, you must make full use of local storage before logging in. The development of local storage based on PhoneGap is implemented using HTML5 's Localstorage function.
Special share with this ~
Built-in Array object member method supplement, remove element array.prototype.remove=function (dx) { if (IsNaN (dx) | | Dx>this.length) { return false; } for (Var i=0,n=0;i<this.length;i++) { if (This[i]!=this[dx]) { this[n++]=this[i] } } This.length-=1}
Shopping Cart class definition cart = function () {this.lstore = Window.localstorage; This.init ();}; cart.prototype={init:function () {var cart_goods_material=this.lstore.getitem (' cart '); try{This.cart_goods=json.parse (cart_goods_material); if (this.cart_goods==null) this.cart_goods=[]; } catch (e) {this.cart_goods=[]; }}, Getall:function () {//Get a list of all items in the shopping cart return this.cart_goods; }, Insert:function (goods) {//Insert commodity var index=this.finds (goods.goods_id); if (index>-1) {this.cart_goods[index].goods_number+=goods.goods_number; }else{This.cart_goods.push (goods); } var cart_goods_cooked = Json.stringify (this.cart_goods); This.lstore.setItem (' cart ', cart_goods_cooked); return true; }, Update:function (Goods_id,data) {var index=this.finds (goods_id); if (index>-1) {for (Var i in DATA) {this.cart_goods[index][i]=data[i]; }} var cart_goods_cooked = Json.stringify (this.cart_goods); This.lstore.setItem (' cart ', cart_goods_cooked); return true; }, Addnum:function (goods_id,num) {//update shopping Cart Merchandise quantity var index=this.finds (goods_id); var num=this.cart_goods[index][' Goods_number ']+num; This.update (goods_id,{' goods_number ': num}); }, Del:function (goods_id) {var index=this.finds (goods_id); This.cart_goods.remove (index), var cart_goods_cooked = json.stringify (this.cart_goods); This.lstore.setItem (' cart ', cart_goods_cooked); return true; }, Finds:function (goods_id) {var index=-1; for (var i in this.cart_goods) {var g=this.cart_goods[i]; if (g.goods_id==goods_id) {index = i; Break }} return index; }, Clear:function () {This.lstore.setItem (' cart ', '); this.cart_goods=[]; }, Amount:function () {var amount=0; for (var i in This.cart_goods) {amount + = this.cart_goods[i][' goods_number ']*this.cart_goods[i][' Goods_price '] ; } return amount; }}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Phonegap+emberjs+python Mobile Store Development, HTML5 realize the local car category ~