Hi,

I'm doing my first real work in clojurescript/om.  I have a little web service 
that queries a database and returns a JSON message of all known schema owners.  
I want to use this data source to populate a dropdown.

The demo page for om-bootstrap is really nice, but in the examples for 
populating a dropdown, the menu-items are known beforehand, so they just nest a 
lot of (menu-item) calls.  I won't know the size of my dropdown until I hit the 
database, and I don't want to spell out each individual menu item....  Is there 
a better way to do this?  I was thinking maybe creating a map of number-string 
pairs, where the keys are menu item keys, and the values are the schema owners. 
 However, I can't think of how I would get around specifying each individual 
menu item.  I tried mapping the menu-item function to no avail.  

The relevant clojurescript looks like this right now:

(ns junk-browser.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [>! <! chan close!]]
              [om.core :as om :include-macros true]
              [om.dom :as dom :include-macros true]
              [om-bootstrap.button :as b]
              [cljs-http.client :as http]))


(defn schema-dropdown [app owner]
  (reify
    om/IInitState
    (init-state [_]
      {:owners []})
    om/IWillMount
    (will-mount [_]
       (go
          (let [owners (into [] (<! (schema-owners)))]  ; (schema-owners) is a 
cljs-http GET
             (om/update-state! owner #(assoc % :owners owners)))))
    om/IRenderState
    (render-state [ _ state]
       (dom/div nil 
                    (b/dropdown {:title "Schema Owners"}
                         (b/menu-item {:key 1} (nth (:owners state) 0 :not-found
                            ...
                          (b/menu-item {:key n} (nth (:owners state) n-1 
:not-found)))))))



Any ideas on how I can tackle this in a better way?

Thanks,

Tom

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to