Want more features on Pastebin? Sign Up, it's FREE!
Guest

opa stringmap iteration issues

By: a guest on Apr 4th, 2012  |  syntax: None  |  size: 0.62 KB  |  views: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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})
clone this paste RAW Paste Data