How can accomplish an if else statement from the underscore template to mustache

Posted by user2942566 on Stack Overflow See other posts from Stack Overflow or by user2942566
Published on 2014-06-10T02:47:35Z Indexed on 2014/06/10 3:25 UTC
Read the original article Hit count: 173

I have an underscore template and I have to use Mustache to render it. Below is my underscore template:

<div id="sub-account">
    <p>something</p>
  <table>
    <tr><td>Name</td>

    </tr>
    <tbody>
        <% _.each(accountList, function(account) { %>
            <tr>
                <td><%= account.get('name') %></td>

            </tr>
        <% }) %>
    </tbody>
  </table>

 </div>

Im using a mustache as my main view to render a list. I also added

_.templateSettings = {
  evaluate    : /\{\[([\s\S]+?)\]\}/g,
  interpolate : /\{\{([\s\S]+?)\}\}/g,
  escape      : /<%-([\s\S]+?)%>/g, 
}; 

to my undersocre.js settings. How can i loop through the code to render as a mustache template. Any ideas???

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about underscore.js