Garces Garces - 1 year ago 102
Javascript Question

Jade template with pure JavaScript

I am using jade template engine in my app and want to remove jquery to check performance. Cannot figure out how to do it with pure JS in this example.

Instead of using jquery as such:

var items = ['it1', 'it2', 'it3'];
var tmpl = require('views/list');
var html = tmpl({ items: App.items });

Template would look as:

each item in items
li= item

Answer Source

See this plunker, it is using pure javascript to display your items:

  var items = ['it1', 'it2', 'it3'];
  var ul = document.getElementById('itemsLists');
  function displayElem(element, index) {
    var li = document.createElement('li');
    t = document.createTextNode(element);
    li.innerHTML=li.innerHTML + element;

script to use after the body

After you can find some template engine js such as pure.js or blueimp to integrate the js into the html but with jade it's not always working (more pure html or ejs).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download