Spring MVC : How to access a modelAndView XML obje

2019-07-26 19:45发布

I have a String variable, containing XML. I added it to my model with modelAndView.addObject(...). Now, how can I access this object in Javascript ?

2条回答
姐就是有狂的资本
2楼-- · 2019-07-26 20:12

Assuming you want to access Model attribute
Using <c:set> like

<c:set var="myData" value="${myObject.data}" />    

and then you can use this var in js using ${myData}.
For example in jQuery selector

<script>
    $("#${myData}").val('foo');
</script>
查看更多
姐就是有狂的资本
3楼-- · 2019-07-26 20:25

Let's say that in your controller you did something like

modelAndView.addObject("someValue", someValue).

In your JSP, you can do this :

<script type="text/javascript">
    var someValue = "${someValue}";
</script>

And then you can use this variable in your JS.

查看更多
登录 后发表回答