SHARE
TWEET

opa stringmap iteration issues

a guest Apr 4th, 2012 15 Never
  1. type item = {string description, string url}
  2.  
  3. database mydb {
  4.   stringmap(item) /items
  5. }
  6.  
  7. /mydb/items["google"] = {description: "search the interwebs with google!", url: "http://google.com"}
  8. /mydb/items["yahoo"]  = {description: "search the interwebs with yahoo!",  url: "http://yahoo.com"}
  9.  
  10. function render_item(item) {
  11. <>
  12.   <li>
  13.     <h4>item</h4>
  14.     <a href="/mydb/items[item]/url">{/mydb/items[item]/description}</a>
  15.   </li>
  16. </>
  17. }
  18.  
  19. function render_index() {
  20. <>
  21. <ul>
  22. {StringMap.iter(function(item) {render_item(item)}, /mydb/items)}
  23. </ul>
  24. </>
  25. }
  26.  
  27. Server.start(Server.http, {title: "test", page: render_index})
RAW Paste Data
Top