我想为列表中的每个项目添加一个点击处理程序。
(defonce selected-department (atom "department!"))
(defn sidebar []
[:div#sidebar-wrapper
[:ul.sidebar-nav
[:li.sidebar-brand [:a {:href "#"} "Departments"]]
;;[:li [:a {:on-click (reset! selected-department "test!")} "Dairy"]]
[:li [:a {:href "#"} "Dairy"]]
[:li [:a {:href "#"} "Deli"]]
[:li [:a {:href "#"} "Grocery"]]]])
然后,selected-department是我想要显示/使用数据的标签
(defn response-box []
[:div#form_comparison
[:label#dlabel @selected-department]])
注释掉的代码片段不起作用。有没有办法让这项工作?
答案 0 :(得分:5)
您的示例无效,因为您必须将函数传递给:on on click,如下所示:
override func viewDidLoad() {
super.viewDidLoad()
addToolBar(addressField)
}
所以你唯一需要改变的是在#reset!...
之前添加#它等同于
[:li [:a {:on-click #(reset! selected-department "test!")} "Dairy"]]
修改:
这是我测试过的完整代码,对我来说很好用:
[:li [:a {:on-click (fn [_] (reset! selected-department "test!"))} "Dairy"]]
单击列表中的项目时,底部的标签会更新。