如何将javascript变量传递给velocity模板

时间:2014-06-29 23:38:34

标签: spring templates velocity jqwidget

我使用jqwidgets创建了一个下拉列表,我使用了速度模板获得了一个表单。在表单操作中,我想获取我的下拉列表的选定值。我需要控制器页面中的值。如何在速度模板变量中获取下拉列表的选定值?我在$ submitUrl.setParameter中传递了这个项目(" filePath"," item")。但如果我在控制器内打印值,那么我只得到项目。不是下拉列表的选定值。任何建议?

<script type="text/javascript">

    $(document).ready(function () 
        {

            // Create the countryjqxWidget DropDownList
            $("#countryjqxWidget").jqxDropDownList({source: countryList, selectedIndex: 0, width: '200', height: '25', theme: 'ui-redmond'}); 


            $('#countryjqxWidget').on('change', function (event)
            {     
                var args = event.args;
                if (args) {
                // index represents the item's index.                      
                var index = args.index;
                var item = args.item;
                // get item's label and value.
                var label = item.label;
                var value = item.value;
                alert(value);
               var item = $("#jqxDropDownList").jqxDropDownList('getSelectedItem');

            } 
            });



         });
</script> 

<form id="form" class="form-horizontal"  action="$submitUrl" method="post" >            
            #lr_btn("submit-btn", "Submit", "Submitting...")
    </form>  



#set( $submitUrl = $renderResponse.createActionURL() )
$submitUrl.setParameter("submit", "upload")
$submitUrl.setParameter("filePath", "item")

1 个答案:

答案 0 :(得分:0)

您是否尝试过添加&#34; countryjqxWidget&#34;在您的表格中并设置其名称&#34;属性。据我所知,如果你设置&#34;名称&#34;属性,选定的值将在表单提交时自动传递。 jQWidgets DropDownList是根据DIV标记创建的,您仍然可以设置其名称&#34;属性。