是否有可能:
1
当我做:
$('#NContrato' ).val('${personList[0].NContrato}');
有用。但如果我这样做
$('#NContrato' ).val('${personList[' + ind + '].NContrato}');
$('#NContrato' ).val('${personList[ind].NContrato}');
$('#NContrato' ).val('${personList[${ind}].NContrato}');
它没有,这是控制器中的 request.setAttribute(personList, ...) (我使用的是 spring MVC)
$('#NContrato' + ind) // JQuery $() ...It works but
${'${personList[' + ind ...} //Request ${} doesn't work concatenating string's
${personList[0].NContrato} // Works
有没有办法做到这一点?
2
我想将 newPerson 更改为 ${personList[0]} 的克隆
我试过这个...
<script type="text/javascript">
function setNewPerson(ind) {
${newPerson=personList[0]};
}
</script>
但是....它给出了这个错误:
org.apache.jasper.JasperException:/WEB-INF/pages/t4imovelZMAguaEdpGass.jsp(153,3) PWC6038:“${newPerson=personList[0]}”包含无效表达式:javax.el.ELException:错误解析:“${newPerson=personList[0]}”
编辑:
JSP
<c:forEach items="${personList}" var="item" varStatus="status">
.....
<button type="button" onclick="change(${item.id},${status.count})"></button>
.....
</c:forEach>
.....
<form:form action="save()" method="post" modelAttribute="newPerson" id="personId" >
....
<form:input path="NContrato" id="NContrato" />
....
</form>
<script type="text/javascript">
function change(id, ind) {
$('#NContrato' ).val('${personList[0].NContrato}'); //Works
var ind=0;
$('#NContrato' ).val("${'personList[' + ind + '].NContrato'}"); // <- 1 Question
....
${newPerson=personList[0]}; // <- 2 Question
}
</script>
控制器(Servlet)
@RequestMapping(value="/saves*", method = RequestMethod.POST )
public @ResponseBody ModelAndView save(@ModelAttribute("newPerson") Person person,
BindingResult errors, HttpServletRequest request) throws Exception {
...
request.setAttribute("newPerson", subForm);
...
request.setAttribute("personList", personManager.getPersonList())
....
return new ModelAndView( "personJSP");
}