简体   繁体   English

使用Noir的webapp:如何在不使用javascript的情况下显示相关的下拉菜单

[英]webapp using Noir: how to display dependent drop-down menus without resorting to javascript

I am trying to write a simple web application using Noir that has a series of drop-down menus whose contents change, depending upon what was selected in the previous drop-down menu(s). 我正在尝试使用Noir编写一个简单的Web应用程序,该应用程序具有一系列下拉菜单,其内容会根据上一个下拉菜单中选择的内容而改变。 These options are then submitted as a form. 然后,这些选项将作为表单提交。 While there exists plenty of information on the web about how to do this using straight-up javascript, I would prefer to stick with Clojure. 尽管网络上有很多有关如何使用纯JavaScript来实现此目的的信息,但我还是希望坚持使用Clojure。 I am using Noir 1.2.1 and Hiccup 0.3.6. 我正在使用Noir 1.2.1和Hiccup 0.3.6。

My current attempt looks something like this (fh is hiccup.form-helpers: 我目前的尝试看起来像这样(fh是hiccup.form-helpers:

(defpage "/run-experiment" []
  (common/layout 
    (fh/form-to [:post "/run-experiment"]
      (fh/label "dd1" "Drop Down 1:")
      (fh/drop-down :opts1 '(Opt1A Opt1B) 'Opt1A)
      (fh/label "dd2" "Drop Down 2:")
      (fh/drop-down :opts2 (cond (= 'Opt1A (get-opt1)) '(Opt2A1 Opt2A2)
                                 (= 'Opt1B (get-opt1)) '(Opt2B1 Opt2B2))))))

(rather than a cond, I'd implement the above with a map, but for now I though this was clearer) (我不是用cond,而是用地图实现了上面的方法,但是现在我虽然更清楚了)

I would like to be able to get the text value of the selected element of the first drop down and display html for the second element based upon that value. 我希望能够获得第一个下拉列表中所选元素的文本值,并基于该值显示第二个元素的html。 I'm trying to figure out if there's a way, using Hiccup, to generate the Javascript necessary for the onclick argument I'll need to add to the first drop-down. 我试图找出是否有一种方法,可以使用打ic来生成onclick参数所需的Java脚本,我需要将其添加到第一个下拉列表中。 Furthermore, I'm trying to figure out if there's a way to access the id value for the other elements of the form so I can link them in the resultant Javascript/HTML. 此外,我试图找出是否存在一种访问表单其他元素的id值的方法,以便可以将它们链接到结果Javascript / HTML中。 Ideally, I'm hoping for something that's like what Hiccup does for HTML, but for Javascript. 理想情况下,我希望能找到与Hiccup一样的HTML,但能像Javascript一样的东西。 I thought Clojurescript might be a good candidate, but it seems like it might be more than what I'm looking for. 我以为Clojurescript可能是一个不错的候选人,但似乎可能超出了我的期望。 I think what I want is a lightweight library that generates strings of common Javascript tasks that can be used in conjunction with Hiccup. 我想我想要的是一个轻量级的库,它可以生成可与Hiccup结合使用的常见Javascript任务的字符串。

I know this is ugly, but you can insert javascript as string literals with hiccup: 我知道这很丑陋,但是您可以使用打ic将javascript作为字符串文字插入:

(hiccup.element/javascript-tag "alert(\"hello world\")")

But then why not just write js.. 但是那为什么不只写js ..

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

相关问题 如何在不使用值的情况下使2个下拉菜单依赖于另一个菜单 - How to make 2 drop down menus dependent on another without using values 使用JavaScript而不使用数据库的动态下拉菜单 - Dynamic drop down menus using JavaScript without using a database javascript函数打破了下拉菜单,但仅在Firefox中 - javascript function breaks drop-down menus but just in Firefox 如何在不重新加载页面或不使用按钮的情况下显示(选择下拉菜单)中选定的文本值 - How to display the selected text value from (select drop-down) without reload the page or using button 使用json数据文件动态创建下拉菜单 - Create drop-down menus dynamically using a json data file 使用php / javascript制作3个从MySQL数据库填充的相关下拉菜单 - Using php/javascript to make 3 dependent drop down menus that are populated from a MySQL database 如何实现如下所示的下拉菜单? - How to implement drop-down menus like below? 如何在Django中读取下拉菜单的内容? - How to read the contents of drop-down menus in Django? 使用JavaScript创建带有对象数组的三级依赖下拉列表 - Creating the three level dependent drop-down list with array of objects using JavaScript 如何验证是否使用JavaScript从下拉列表中未选择任何内容 - how to validate if nothing is selected from drop-down using JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM