用javascript数组填充struts2选择标签 [英] Fill struts2 select tag with javascript array

查看:92
本文介绍了用javascript数组填充struts2选择标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在加载时使用javascript数组填充Struts 2选择标签?



我有一个代码

 < s:select id =attrStpSelname =attrStpSelheaderKey = -  1
headerValue =Selectlist =$ {attributeActions}
labelposition =leftonchange =displaySelectAction()
cssStyle =width:300px; />

这是页面中的脚本。



< pre class =lang-jsp prettyprint-override> < script type =text / javascript>
$(document).ready(function(){
var attributeActions = ['Add','Update','Search'];
});
< / script>

由于它是一个硬编码值,我不希望它们从行为中填充。使用上面的代码,javascript变量 attributeActions 没有被拾取。



将静态列表填充到Struts 2 select标签中的理想方式是什么?

解决方案

您可以使用#{} 创建一个内联列表:

< s:select name =attrStpSel
headerKey =-1
headerValue =Select
list =#{'Add','Update','Search'}/>

您也可以使用相同的表示法创建内嵌地图:

 < s:select name =attrStpSel
headerKey =-1
headerValue =Select
list =#{'0':'添加','1':'更新','2':'搜索'}/>


Is it possible to fill the Struts 2 select tag with javascript array on load?

I have a code

<s:select id="attrStpSel" name="attrStpSel" headerKey="-1"
          headerValue="Select" list="${attributeActions}"
          labelposition="left" onchange="displaySelectAction()"
          cssStyle="width: 300px;" />

This is the script in the page.

<script type="text/javascript">
    $(document).ready(function() {
        var attributeActions = [ 'Add', 'Update', 'Search' ];
    });
</script>

Since it is a hard coded values, I don't want them to be populated from action. with the above code the javascript variable attributeActions is not being picked up.

What should be the ideal way to populate the static list into the Struts 2 select tag?

解决方案

You can create an inline list with #{}:

<s:select name = "attrStpSel" 
     headerKey = "-1"
   headerValue = "Select" 
          list = "#{'Add','Update','Search'}" />

You can also create an inline map with the same notation:

<s:select name = "attrStpSel" 
     headerKey = "-1"
   headerValue = "Select" 
          list = "#{'0':'Add' , '1':'Update' , '2':'Search'}" />

这篇关于用javascript数组填充struts2选择标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆