开发者

setting a javascript variable to a struts property map value

开发者 https://www.devze.com 2023-01-30 04:32 出处:网络
basically I want to do the following. var myvar = \'<s:property value=\"myMap[\'mapKey\'].mapObjectValue\" />\'

basically I want to do the following.

var myvar = '<s:property value="myMap['mapKey'].mapObjectValue" />'

but that fails. I've tried several variations of qu开发者_如何学Gootes and can't quite get it to work correctly. any ideas?

I can do this:

var myVar = <s:property value="myMap['mapKey'].mapObjectValue" />;

but then the javascript variable isn't a string, so I can't use it as needed.


If your first attempt is failing, I'm guessing that the problem is in the Javascript parsing. You might want to try escaping the string for Javascript, using Apache Commons Lang for example:

var myvar = '<s:property value="@org.apache.commons.lang.StringEscapeUtils@escapeJavaScript(myMap['mapKey'].mapObjectValue)" />';


It should be working, as the tag will be rendered before Javascript gets interpreted. If javascript value isn't getting setted properly, maybe

<s:property value="myMap['mapKey'].mapObjectValue" />

isn't returning the correct value.

As @BalusC said, theres is no need to make javascript compile on your IDE.

0

精彩评论

暂无评论...
验证码 换一张
取 消