phonegap+emberjs+python手機店發展,html5實現本地車類別~

來源:互聯網
上載者:User

標籤:

商城開發項目,現在需要做出APP,無奈出場前android但不是很精通。最後選擇phonegap實現app。

由於之前辦理購物車分為登陸和登陸後兩種情況,登入前必須充分利用本機存放區。而基於phonegap本機存放區的發展是使用Html5的localstorage功能實現。

特分享與此~

//內建數組對象成員方法補充,移除元素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}
            
            
//購物車類定義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(){                   //獲得購物車全部商品列表        return this.cart_goods;    },    insert:function(goods){              //插入商品        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){      //更新購物車商品數量        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;    }}


著作權聲明:本文部落格原創文章。部落格,未經同意,不得轉載。

phonegap+emberjs+python手機店發展,html5實現本地車類別~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.