簡體   English   中英

如何完成從下划線模板到小胡子的每次循環

[英]How can accomplish For-Each loop from the underscore template to mustache

我有一個下划線模板,必須使用Mustache進行渲染。 下面是我的下划線模板:

<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>

我使用胡須作為我的主要視圖來呈現列表。 如何遍歷代碼以呈現為小胡子模板?

骨干收集:

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

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

   return SubAccountCollection;
 });

這就是我試圖用ajax調用做的事情:

accountList.fetch({

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

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

應該是這樣的。 沒有檢查。

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

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

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

 </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM