【问题标题】:How to access the java List of a custom class objects specified in <s:iterator> tag of jsp file inside my javascript function?如何访问我的javascript函数中jsp文件的<s:iterator>标签中指定的自定义类对象的java列表?
【发布时间】:2014-08-11 09:13:43
【问题描述】:

我有一个 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>

请给我一些建议 我已经厌倦了 2 天以来的护目镜

【问题讨论】:

  • 你确定它不工作吗?您是否尝试使用 标签打印它?
  • 据我所知 只能在 JSP/HTML 中使用,但我想访问 javascript 代码中的类对象。我是 JavaScript 新手。你能详细解释一下你的建议吗?
  • 我只是说你确定这个变量包含一些值吗?使用 JSTL 在 jsp 上列出这些值以确认。

标签: java javascript jquery iterator


【解决方案1】:

我认为问题在于您试图将一些非原始类型的列表分配为 JavaScript 数组。

This的回答可能对你有帮助。简而言之,您可能需要进行一些转换,而不是直接分配此对象。由于链接的答案使用静态实用程序方法,您可能需要考虑在后端进行转换。

【讨论】:

    猜你喜欢
    • 2011-05-09
    • 2011-02-26
    • 2015-09-01
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    相关资源
    最近更新 更多