简体   繁体   English

如何访问在中指定的自定义类对象的Java列表 <s:iterator> 我的javascript函数中的jsp文件标签?

[英]How to access the java List of a custom class objects specified in <s:iterator> tag of jsp file inside my javascript function?

I have jsp file in which i am getting a List of objects from my java action class (struts2) and displaying it.Now i want to access these list objects inside my javascript method.How to do this? 我有一个jsp文件,我正在从Java动作类(struts2)获取一个对象列表并显示它。现在我想在javascript方法中访问这些列表对象。

mycode.jsp 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>

Please give me some suggestions I am tired of goggling since 2 days 请给我一些建议,我已经厌倦了两天以来的闲聊

I believe the problem is that you are attempting to assign a list of some non-primitive type as a JavaScript array. 我相信问题是您正试图将某些非原始类型的列表分配为JavaScript数组。

This answer may be helpful to you. 这个答案可能对您有帮助。 In short, you may need to do some converting rather than directly assigning this object. 简而言之,您可能需要进行一些转换,而不是直接分配此对象。 Since the linked answer uses a static utility method, you may need to consider doing the conversion on your backend. 由于链接的答案使用静态实用程序方法,因此您可能需要考虑在后端进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM