2014-06-29 46 views
0

我使用jqwidgets創建了一個下拉列表,並且我使用velocity模板獲得了一個表單。在表單操作中,我希望獲取我的下拉列表的選定值。我需要在我的控制器頁面中的值。我怎樣才能得到速度模板變量內的dropdownlist的選定值?我在$ submitUrl.setParameter(「filePath」,「item」)中傳遞了這個項目。但如果我打印控制器內的值,那麼我只能獲得項目。不是下拉列表的選定值。任何建議?如何將javascript變量傳遞給速度模板

<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") 

回答

0

您是否試過在表單中​​添加「countryjqxWidget」並設置其「名稱」屬性。據我所知,如果你設置了「name」屬性,所選的值將在表單提交時自動傳遞。不要緊,jQWidgets DropDownList是從DIV標籤創建的,你仍然可以設置它的「name」屬性。

+0

非常感謝。我試着用你的方式。它工作得很好:-) – stack

相關問題