Ajax, HJS and Mustache

1

I do not like writing HTML in Ajax, like this ...

    var orderTemplate = "" +
"<li data-id='{{_id}}'" +
"<p><strong>Nome:</strong> <span class='noedit nome'>{{ nome }}</span>" +
"<input class='edit nome'> </p> "+
"<p><strong> Bebida: </strong><span class='noedit bebida'>{{ bebida }}</span>" +
"<input class='edit bebida'> </p> " +
"<button data-id='{{_id}}' class='remove'> X </button>" +
"<button class='editOrder noedit'> Editar </button>" +
"<button class='saveEdit edit'> Salvar </button>" +
"<button class='cancelEdit edit'> Cancelar </button>" +
"</li>";

function addOrder(order) {
    $orders.prepend(Mustache.render(orderTemplate, order));
}

So I researched the html template tag, which imports a html ajax. This part I was able to do, but I can not bring the variables {{name}} and {{drink}} to be printed on the screen. And with the above code, inside ajax, the variables are printed on the screen. It's the same code, but the html template does not work. I use Mustache | hjs to render views.

    
asked by anonymous 17.05.2018 / 00:17

1 answer

1

Good afternoon, do as follows <span class='noedit nome'>" + {{ nome }} + "</span>" + .... you have to remove the variables from within the string and concatenate them in the string ....

    
17.05.2018 / 19:35