本文介绍了如何完成从下划线模板到胡须的For-Each循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下划线模板,必须使用胡子进行渲染.下面是我的下划线模板:

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?

骨干网收藏

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

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

   return SubAccountCollection;
 });

这就是我试图使用ajax调用的方式:

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)
                }
            });

推荐答案

应该是这样的.没检查.

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>

这篇关于如何完成从下划线模板到胡须的For-Each循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 10:30