Hi Everyone,
I have been coding clojure for a few months and I've just started
using clojurescript and I am struggling to use for forms inside event
handlers. Sorry if this is covered elsewhere but I have searched as
best I can without finding the answers.
I have an event handler that listens for changes in an <input> element
(def search-input (dom/get-element "search"))
(def test-area (dom/get-element "test-area"))
(event/listen search-input
:keyup
(fn [e]
(let [search-results ["a" "b"]]
(dom/append test-area (dom/element :p {} (first search-
results)))
(dom/append test-area (dom/element :p {} (second search-
results))))))
It works fine. Everytime I type in the input box, some text is
appended to 'test-area'
However, this doesn't work any more when I switch to using for
(event/listen search-input
:keyup
(fn [e]
(let [search-results ["a" "b"]]
(for [x search-results] (dom/append test-area (dom/element :p {}
x))))))
Stepping through the generated code, I noticed that the generated
javascript calls the function with null as the first argument (second
last line below) but I can't figure out why or how to change the
behaviour.
clojure.browser.event.listen.call(null,
smws_numbers.cljs.smws_numbers.search_input, "\ufdd0'keyup",
function() {
return function b(c) {
return new cljs.core.LazySeq(null, !1, function() {
for(;;) {
if(cljs.core.truth_(cljs.core.seq.call(null, c))) {
var d = cljs.core.first.call(null, c);
return cljs.core.cons.call(null,
clojure.browser.dom.append.call(null,
smws_numbers.cljs.smws_numbers.test_area,
clojure.browser.dom.element.call(null, "\ufdd0'p",
cljs.core.ObjMap.fromObject([], {}), d)), b.call(null,
cljs.core.rest.call(null, c)))
}
return null
}
})
}.call(null, cljs.core.Vector.fromArray(["a", "b"]))
});
I fell sure I'm missing something fairly basic, but it's escaping me
for now so any help you can provide would be greatly appreciated.
Many Thanks
Adrian
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en