[英]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.