【问题标题】:How can I show data in display:table from .json function?如何在 display:table 中显示来自 .json 函数的数据?
【发布时间】:2014-09-01 08:01:33
【问题描述】:

我有一个 .json 函数,它检索一些数据,我想用 <display:table> 显示它,我该怎么做

Alerta.js

function loadAlertaCitas(){
    $.ajax({
        type: "GET",
        url: contextpath+"/alerta/cargaAlertas.json",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data) {
            listaAlertas =  data;
        }
    });
}

Alerta.jsp

<display:table name="listaAlertas" id="alertas"
                                defaultorder="descending" requestURI="/other/listaAlertas" pagesize="12"
                                class="table table-striped table-condensed">

                                <display:column property="fechaalta" titleKey="label.fechaAlta"
                                    sortable="true" class="ancho90" />

                            </display:table>

【问题讨论】:

  • 为什么在 GET 请求中有contentType: "application/json; charset=utf-8",? GET 请求中没有请求正文,因此没有什么可以描述其内容类型。

标签: javascript json spring-mvc


【解决方案1】:

JSP 在服务器上执行。 JavaScript(在此上下文中)在浏览器中执行。

您无法使用 JavaScript 生成 JSP 标记,因为将它们转换为 HTML 的软件存在于错误的计算机上。

您需要在浏览器中操作文档的 DOM。使用createElementcreateTextNodeappendChildfriends

【讨论】:

    【解决方案2】:

    您可以在服务器端执行此操作。读取json文件并在jsp模板的render方法中加载display:table

    request.setAttribute('listaAlertas', jsonData);

    More info.

    如果您坚持从浏览器动态加载,则需要按照建议操作 dom。在这种情况下,您不能使用display:table,因为它是在服务器上呈现的。

    More info

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 2018-10-01
      相关资源
      最近更新 更多