![](/img/trans.png)
[英]How to access a java list coming from the server in javascript inside my 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.