从后来返回一个list的话,现在在页面table里显示出来,但是回传的list排序有些问题,我想根据list[i].id和list[i].prop两个字段来进行排序。
举例:
list里有5条数据
{id:01,prop:0,belong:Scott,com:Company A},
{id:01,prop:0,belong:Scott,com:Company A},
{id:02,prop:0,belong:Smith,com:Co.B },
{id:01,prop:1,belong:Anderson,com:Company A},
{id:01,prop:1,belong:Scott,com:Company A}
页面效果:如何操作此list可以达到如上页面效果

解决方案 »

  1.   

    list最后一条数据belong应为Anderson
      

  2.   

    问题阐述不清晰你是要对 list的数据进行排序
    还是要把list的数据 变成 table?
      

  3.   

    是这样,针对2楼的问题,我想说控制肯定是针对list的,等到页面的时候就剩一个个foreach出来了,页面显示的时候肯定都排序完毕
      

  4.   

     <style>
        table{ border-collapse:collapse; }
        td{border:1px solid #000; }
    </style>
    <table border=1 id="t1" >
    <tr>
    <td>id</td><td>prop</td><td>belong</td><td>com</td>
    </tr> 
    </table> 
     
     
    <script>
    var ds=[{id:'01',prop:'0',belong:'Scott',com:'Company  A'},
    {id:'01',prop:'0',belong:'Scott',com:'Company  A'},
    {id:'02',prop:'0',belong:'Smith',com:'Co.B'},
    {id:'01',prop:'1',belong:'Anderson',com:'Company  A'},
    {id:'01',prop:'1',belong:'Scott',com:'Company  A'}];
    ds.sort(function(a,b){
     return a.id+a.prop >  b.id+b.prop ?1:-1 
    });
    t1=document.getElementById('t1');
    var cls='id prop belong com'.split(' ');
    for(var i=0;i<ds.length;i++){
     var r= t1.insertRow(-1);
    for(k in ds[i]) r.insertCell(-1).innerHTML=ds[i][k];
    }function mergeCell(tb,i){
        var rs=tb.rows,ac,acv;
        if(!rs.length) return;
        for(var r=0;r<rs.length;r++){
            var cs=rs[r].cells, c=cs[i];
            if( !ac|| (c.innerHTML!=ac.innerHTML ) ){
                ac=c;
            }else{
              ac.rowSpan++;
              c.style.display='none'
            }
        }
    }
    mergeCell(t1,2);
    mergeCell(t1,3);
     
    </script>