Ajax, HJS and Mustache

Asked

Viewed 28 times

2

I don’t 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 looked up the html tag template, which matters to ajax an html. This part I managed to do, but I can’t bring the variables {{name}} and {{drink}} to be printed on the screen. And with the above code, inside the ajax, the variables are printed on the screen. It’s the same code, but the html template does not work. Using Mustache | hjs to render views.

1 answer

2


Good afternoon, do it this way <span class='noedit nome'>" + {{ nome }} + "</span>" +.... you have to remove the variables from inside the string and concatenate them into the string....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.