我有一个 JSP 页面,第一次使用项目列表调用该页面。 在选择下拉列表(选择)时,我触发 AJAX 代码来获取特定于所选选项的产品,并且我想用更相关的产品覆盖产品列表。
有没有办法将其设置为“${products}”,或者我是否必须使用其他方法,例如隐藏该 div 标签并显示另一个标签。
我的JSP页面
<div>
<c:forEach var="p" items="${products}">
<table>
<td>p.name</td>
<td>p.description</td>
</table>
</c:forEach>
<div>
我的脚本
// Ajax...
success: function(result) {
if (result.length > 0) {
// want to set the products list with the list returned
}
}
我的 Controller
public List<Product> MyController() {
// ...
List<Product> products = prodcat.getList()
return products
}
最佳答案
感谢您的回复,让我告诉您我的方法。我使用 AJAX Jackson 并尝试将产品列表传递到 View 。我在对象转换中隐式地在我的产品(一个)和评级(许多)之间建立了双向映射,它进入了无限循环,因为它在产品中查找评级和评级中的产品。 我创建了另一个 Model 类,并仅设置了 products 类中我需要的属性,而不是发送产品列表。 所以最后我只是用收到的新元素覆盖了 div 标签。
关于jquery - 如何使用 EL 将 AJAX 返回的列表设置为页面上的列表引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43566690/