我有 jsp 文件,其中我从 java 操作类 (struts2) 获取对象列表并显示它。现在我想在我的 javascript 方法中访问这些列表对象。如何执行此操作?
mycode.jsp
<script type="text/javascript">
//Some functions
jQuery(document).ready(function(){
$("#dialog-form").trigger('click');
//Problem is how to access myObjectsList here
//and which is of type MyCustom class with 2 class variables(i.e., name and id)
//I need to access name and id as well
var colFamilies ='${myObjectsList}';
alert(myObjectsList);
});
//Some functions
</script>
<html>
<!-- my code -->
<s:iterator value="myObjectsList" var="myObject">
<li><h4>
<s:property value="#myObject.name" />
</a>
</h4></li>
<!-- my code -->
</html>
请给我一些建议 两天以来我已经厌倦了护目镜
最佳答案
我认为问题在于您正在尝试将某些非基本类型的列表分配为 JavaScript 数组。
This答案可能对你有帮助。简而言之,您可能需要进行一些转换,而不是直接分配该对象。由于链接的答案使用静态实用程序方法,您可能需要考虑在后端进行转换。
关于java - 如何访问 <s :iterator> tag of jsp file inside my javascript function? 中指定的自定义类对象的 java 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24330199/