日期:2014-05-16  浏览次数:20348 次

数组重组
JScript code

function aaa(){
    var aa={data:[{type:1,name:"dsaf"},{type:2,name:"sdfsf"},{type:3,name:"terte"},{type:1,name:"eqweqw"},{type:1,name:"hgfhgfh"},{type:2,name:"dad"},{type:1,name:"jghjh"},{type:3,name:"dads"}]};
    var a1=[],a2=[],a3=[],len=0;
    
    len = aa.data.length
    
    for(var i =0; i<len; i++){
        if(aa.data[i].type==1){
            a1 += aa.data[i]
        }else if(aa.data[i].type==2){
            a2 += aa.data[i]
        }else if(aa.data[i].type==3){
            a3 += aa.data[i]
        }
    }
}



现在 a1,a2,a3都是空数据

------解决方案--------------------
a1 += aa.data[i] => a1.push(aa.data[i])

后面的也是这样改
------解决方案--------------------
JScript code
<script type="text/javascript">
 var aa={data:[{type:1,name:"dsaf"},{type:2,name:"sdfsf"},{type:3,name:"terte"},{type:1,name:"eqweqw"},{type:1,name:"hgfhgfh"},{type:2,name:"dad"},{type:1,name:"jghjh"},{type:3,name:"dads"}]};
 var a1=[],a2=[],a3=[],len=0;
    for(var i=0;i<aa.data.length;i++){
        window["a"+aa.data[i].type].push(aa.data[i].type);
        //window["a"+aa.data[i].type].push(aa.data[i].name); 我怎么感觉你需要的是这个
    }
</script>