How can accomplish For-Each loop from the undersco

2019-08-10 14:23发布

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. How can I loop through the code to render as a mustache template?

Backbone Collection:

var SubAccountCollection = Backbone.Collection.extend({
    initialize: function(models, options) {
        this.account = options.id;
    },

    url: function() {
        return 'some/' +this.account + '/somelist';
    }
});

   return SubAccountCollection;
 });

This is what im trying to do with the ajax call:

accountList.fetch({

                success: function(accnlist){
                    setInterval(function(){
                        $('#sub-account-list').html(tmpl, {accnlist:accnlist.toJSON()})
                    }, 500);

                },
                error: function(err){
                    console.log('Error!', err)
                }
            });

1条回答
做自己的国王
2楼-- · 2019-08-10 15:19

should be something like that. didn't check though.

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

    </tr>
    <tbody>
        {{#accountList}}
            <tr>
                <td>{{name}}</td>

            </tr>
        {{/accountList}}
    </tbody>
  </table>

 </div>
查看更多
登录 后发表回答