syndicatefx
9/28/2015 - 8:49 PM

Iterating over json data using jade + harpjs

Iterating over json data using jade + harpjs


//- Use case example: list browser usage data(retrieved from _data.json file) separated by desktop and mobile

h3 Desktop

ul
  each browserDesktop in public._data.browserDesktops
    li
      span= browserDesktop.total + "%"
      span= browserDesktop.name

h3 Mobile

ul
  each browserMobile in public._data.browserMobiles
    li
      span= browserMobile.total + "%"
      span= browserMobile.name
{
  "browserDesktops":[
    {"name":"chrome", "total":"63"}, 
    {"name":"ie", "total":"17"},
    {"name":"firefox", "total":"14"}, 
    {"name":"safari", "total":"3"}, 
    {"name":"opera", "total":"1"}, 
    {"name":"outros", "total":"0"} 
  ],

  "browserMobiles":[
    {"name":"chrome", "total":"37"},
    {"name":"safari", "total":"31"},
    {"name":"android", "total":"24"},
    {"name":"IE Mobile", "total":"2"},
    {"name":"ie", "total":"1"},
    {"name":"opera", "total":"0"},
    {"name":"firefox", "total":"0"},
    {"name":"outros", "total":"1"}
  ],
}