使用ajax调用填充显示表 [英] Use ajax call for fill display table

查看:150
本文介绍了使用ajax调用填充显示表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Portlet和Spring MVC.我想通过ajax调用获取项目列表,并将该列表用作display:table属性.

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.

我使用这个ajax调用:

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.

我的问题是:如何用我刚刚得到的列表生成displaytable?

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

有没有一种方法可以更新显示:使用该列表在jsp中定义的表?

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

我定义的显示将检索requestScope的列表,但我想通过ajax调用来检索该列表.

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

我的显示:表格:

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

推荐答案

我的问题是:如何用我刚刚得到的列表生成displaytable?

根据我的经验,您的列表必须包含json数据映射,例如:

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();

pList包含产品图.

The pList is contains Map of product.

有一种方法可以更新显示:在jsp中使用该列表定义的表?

是的,在我使用Firebug检查了显示表标签部分之后,我发现显示表标签将更改为普通的html表.因此,在 ajax 中:

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);
    }                   

},

和您的显示标签:

<display:table id="docentes" pagesize="4" class="displayTagTable" uid="docente">
    <display:column escapeXml="true" title="Product Name" >
    </display:column>                                                                                 
</display:table>

这篇关于使用ajax调用填充显示表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆