Use ajax call for fill display table

2019-09-07 22:50发布

I'm working with portlets and spring MVC. I want to get a list of items with an ajax call and use that list as the display:table attribute.

I use this ajax call:

jQuery.ajax({ url:'<portlet:resourceURL id="recuperarDatosAF">
 </portlet:resourceURL>', data: {idExpediente:expediente}, type: 'POST',
  datatype:'json', success: function(data) { 
      alert(data); 
  } 

This call is executed each time the user selects an item of a combo. the list of items that will be different each time recovered.

My question is: How could generate displaytable with that list I just get?

There a way to update a display: table defined in the jsp with that list?

The display that I have defined, retrieves the list of requestScope but I want to retrieve the list with ajax call.

My display:table:

       <display:table id="docentes" name="${requestScope.docentesList}"                       
                                           htmlId="resultadosDocentesListTable"
                                           pagesize="4"
                                           class="displayTagTable"
                                           uid="docente">

2条回答
叼着烟拽天下
2楼-- · 2019-09-07 23:42

http://jsfiddle.net/kVdZG/

Script to generate a table from json data, replace alert(data) with this code, here data.scores is my data

var data = { "scores" : [ ["3/1/2011", 610],["4/1/2011", 610],["5/1/2011", 610],["6/1/2011", 610], ["7/1/2011", 720], ["8/1/2011", 500], ["9/1/2011", 500] ] }



$(data.scores).each(function(index, element){
         $('#scores').append('<tr><td> '+element[0]+' </td> <td> '+element[1]+' </td></tr>');       
    })
查看更多
虎瘦雄心在
3楼-- · 2019-09-07 23:42

My question is: How could generate displaytable with that list I just get?

From my experience, your list must contains Map of json data eg:

Map productMap = new HashMap();

    productMap.put("id", "1");
    productMap.put("name", "Coca Cola");                

    List<Product> productList = new ArrayList<Product>();
    productList.add(productMap);

    jsonWriter.object()
        .key("status").value(true)                   
        .key("pList").value(productList)
        .endObject();

The pList is contains Map of product.

There is a way to update a display: table defined in the jsp with that list?

Yup, after I check the display table tag part using firebug, I have found out that the display table tag will be change to normal html table. So in ajax:

success: function(data){
    if(data.status == true){
        var strHtml='';                
        for(var i=0;i<data.pList.length;i++){
        strHtml+='<tr><td>'"+data.pList[i].name+"'</td></tr>';   
        }
    jQuery("table#docentes tbody").html(strHtml);
    }                   

},

and your display tag:

<display:table id="docentes" pagesize="4" class="displayTagTable" uid="docente">
    <display:column escapeXml="true" title="Product Name" >
    </display:column>                                                                                 
</display:table>
查看更多
登录 后发表回答