来自 jsp 和 javascript 中的请求属性的对象索引数组
Array of object's index from request attribute in jsp and javascript
是否可以:
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
有没有办法做到这一点?
阿拉伯数字
我想改变新人拥有克隆${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");
}
如果你开始使用EL编写JSP代码,而没有首先学习基础知识,原始的旧做事方式,你将永远感到困惑。EL 的 ${} 看起来有点像 jquery 的 $(( 运算符,但事实并非如此。
EL 表达式
${personList[0].NContrato}
相当于
<%= personList[0].NContrato %>
或
<% out.print( personList[0].NContrato ); %>
它在服务器端运行并打印 personList[0] 的值。NContrato到您正在构建的HTML源代码中。
表达式
${personList[' + ind + '].NContrato}
什么都不做。 为什么? 因为 ${} 在服务器上运行并且只打印变量。 没有名为"personList[' + ind + ']的变量。NContrato"。 确切的文本"${personList[' + ind + ']。NContrato}"将被打印到您的 HTML 源代码中。 因此,在故障排除时在浏览器中查看源代码非常重要。
至于
${newPerson=personList[0]};
你不能在EL中做这样的作业。 问问自己,以下内容是否有意义?
<% out.print( newPerson=personList[0] ); %>
在打印命令中执行作业是没有意义的。
- 为什么我可以在Array属性对象中找到Javascript Array for Each方法
- 使用onclick调用属性对象函数
- 嵌套为..in 循环,列出多维对象的属性(对象)
- 动态属性对象 - JSON
- 在不使用隔离范围angularjs自定义指令的情况下获取属性对象
- 通过属性传递属性/对象.Javascript
- Javascript:属性/对象的类型
- 访问JSON中的属性(对象)
- 属性对象Javascript不是用Jquery Deferred设置的
- 无法读取属性'#<对象>'未定义的获取错误
- Twitter中多属性对象的子字符串匹配
- 无法设置'data'属性'对象'标记.(只IE8)
- 更新数据属性对象属性值
- 将属性对象的选定对象从原型推入数组
- 将单个属性对象字面量的数组转换为仅包含其值的数组的最佳方法
- 寻找一种更简单的方法来检查是否多个属性&对象中的方法是未定义的
- 主干模型:带有get方法的空属性,但在属性对象中
- 如何赋值给"text"someText"属性对象在动能js
- Angularjs的数据绑定与数据属性对象
- 如何将一个嵌套的javascript对象转换为只有一级属性对象