vue.js中的两种遍历方式(以及substring,split,getJsonLength)

来源:互联网 发布:java 设计模式 面试 编辑:程序博客网 时间:2024/05/21 21:38

第一种:

 $.each($('.active'), function(index, item){    attrTxt+= (' ' + $(item).text());    attrid+= ($(item).attr('attrid')+'|');    });

注意:
$(‘.active’) —-指的是:class=active的对象可能为多个span标签组成的对象

第二种:

this.pro.forEach(function (item) {                           if(item.goods_attr==attrid){this.goods_num=item.product_number;                           }else{                               self.goods_num=0;                           }                       });

注意:this.pro—-指的是:也是一个对象

attrid=attrid.substring(0,attrid.length-1);  attrArr=attrid.split('|');attrLength=self.getJsonLength(self.goods.attr_info);substring(开始位置,结束位置)  字符串截取 split(分隔符)                 把字符串转化成数组getJsonLength(数组)         得到长度