phonegap+emberjs+python手机店发展,html5实现本地车类别~

phonegap+emberjs+python手机店发展,html5实现本地车类别~

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

商城开发项目,现在需要做出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;
    }
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117574.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • PLSQL Developer 安装使用教程详解

    PLSQL Developer 安装使用教程详解下载plsqldeveloper:官网下载:https://www.allroundautomations.com/registered-plsqldev/我下载的是10.0.3这个版本,目前版本已经达到了14,下载后顺带把ChineseLanguagepack下载一下,一会可以将软件的语言改为中文;安装plsqldeveloper下载完成后:选择plsqldev文件(注意这里标注的默认安装路径需要修改,改成路径中不含空格和中文的路径,否则,安装了,无法进行远程连接。)安

    2022年6月6日
    54
  • go语言IP转换uint32,uint32转换IP「建议收藏」

    go语言IP转换uint32,uint32转换IP「建议收藏」uint32类型转换为IPfuncUInt32ToIP(intIPuint32)net.IP{   varbytes[4]byte   bytes[0]=byte(intIP&amp;0xFF)   bytes[1]=byte((intIP&gt;&gt;8)&amp;0xFF)   bytes[2]=byte((intIP&gt;&gt…

    2025年9月28日
    4
  • 内网ip和外网ip区别

    内网ip和外网ip区别文章一:原文:https://blog.csdn.net/Alexwym/article/details/81772446我们每天都会访问各种各样的网站,比如淘宝,百度等等。不免会思考,我们的设备是如何连接上这些网址的呢?要想搞清楚这个问题,首先就得先搞清楚内网ip和外网ip的联系。如图,假设我们的计算机现在就是设备一,我们想要访问百度。如果我们正使用着校园网,那么首先我们需要先通…

    2022年6月14日
    39
  • web前端node.js常用命令

    web前端node.js常用命令1、npm install moduleNames:安装Node模块安装完毕后会产生一个node_modules目录,其目录下就是安装的各个node模块。node的安装分为全局模式

    2022年7月1日
    19
  • Linux下chkconfig命令详解

    Linux下chkconfig命令详解

    2021年10月28日
    52
  • IdeaVim-常用操作「建议收藏」

    IdeaVim-常用操作「建议收藏」IdeaVim简介IdeaVim是IntelliJIDEA的一款插件,他提高了我们写代码的速度,对代码的跳转,查找也很友好。安装位置安装之后它在Tools>VimEmulator具体操作i模式i模式即为编辑模式,按下字母i开启就可以打字。Esc从i模式切换为Vim,按下键盘的Esc键切回Vim。方向键上:k,下:j,左:h,右:…

    2022年5月5日
    195

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号