简体   繁体   English

速度-基于哈希图的下拉列表,在选择时显示值

[英]Velocity - dropdown based on hashmap, display values on selection

I have a HashMap< String, List< Integer>> . 我有一个HashMap< String, List< Integer>> Is it possible for me to display a dropdown box in velocity based on the String keys in the HashMap and when the user makes its selection to display the List< Integer> below the dropdown? 我是否可以基于HashMap的String键在速度上显示一个下拉框,并且当用户进行选择以在下拉列表下方显示List< Integer>

Velocity is server side, HTML lives in a browser on the client side. Velocity是服务器端,HTML驻留在客户端的浏览器中。 When the user interacts with page, Velocity has long since ceased to be executed. 当用户与页面进行交互时,Velocity早已停止执行。 So no, you can not use values from the live DOM in Velocity. 因此,不能,您不能在Velocity中使用实时DOM中的值。 You can, however, send back the selected value to Velocity: 但是,您可以将所选值发送回Velocity:

  1. Render the initial HTML page with a <select> that lists the top level options, in a <form> 使用<form><form>呈现初始HTML页面,其中<select>列出了顶级选项。
  2. The user selects something from the <select> and submits the form 用户从<select>选择某项并提交表单
  3. Back on the server, Velocity can then read the selected value from the request and generate a new HTML with the second level options 回到服务器上,Velocity随后可以从请求中读取所选值,并使用第二级选项生成新的HTML。

If you don't want two page loads, you can either use an AJAX request to get just the list of valid values, or you can send the whole map in the first step (hidden in the HTML) and process it clientside with JavaScript. 如果您不希望加载两个页面,则可以使用AJAX请求仅获取有效值列表,也可以在第一步中发送整个地图(隐藏在HTML中)并使用JavaScript在客户端进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM