簡體   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?

我有一個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數組。

這個答案可能對您有幫助。 簡而言之,您可能需要進行一些轉換,而不是直接分配此對象。 由於鏈接的答案使用靜態實用程序方法,因此您可能需要考慮在后端進行轉換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM