BackboneJs-如何调用api并遍历每个帐户以显示数据

时间:2014-06-22 07:49:42

标签: html api backbone.js underscore.js

我有一个帐户名列表和一个指示与该帐户关联的用户的附加列。我希望调用用户API来显示帐户名称旁边的列表: 以下是快照: enter image description here

我正在获取名称'字段呼叫api" '1.0/api/accountlist/'+accountid.现在,我需要单独拨打用户的电话号码'1.0/api/userlist/,以便让用户'领域。有什么方法可以做到这一点吗? 在我看来我的观点:

var SubAccountList = Backbone.View.extend({
        initialize: function(){
        },

        el:$("#sub-account-list"),

        render: function(id){   
            console.log(id);
            var self = this;
            var subaccountList = new SubAccountCollection([],{ id: id });
            subaccountList.fetch({
                success: function(subaccountLists){                     
                    var data = subaccountLists.toJSON();
                    var subaccounts = data[0].data.items;               
                    //var template = $("#sub-account-list").html(_.template(tmpl, {accountLists:accountLists.toJSON()}));
                    var template = $("#sub-account-list").html(_.template(tmpl, {subaccounts:subaccounts}));
                    $("#table").tablesorter( {sortList: [[0,0], [1,0]]} );                                                              
                },
            });
        }
    });

HTML:

<table id="table" class="tablesorter tablesorter-default tabular" role="grid">
                 <thead>
                <tr>
                <th>Status</th>
                <th>Name</th>
             </tr>
            </thead>
                    <tbody>
                        <% _.each(subaccounts, function(account) { %>
                        <tr>            
                            <td><%= (account.active == 'true') ? 'Inactive': 'Active' %></td>
                            <td><a href="#edit/<%= account.id %>"><%= account.name%></a></td>
                        </tr>
                        <% }) %>
                </tbody>
            </table>

JSON我将回复呼叫用户的api:

{
"data": {
    "more": true,
    "offset": 0,
    "total": 20,
    "items": [
        {
            "active": true,
            "role": "student",
            "contactInfo": {
                "firstName": "john",
                "lastName": "olive",
                "email": "j.olive@gmail.com"
            }]
           }}

我尝试为用户检索的字段是"total": 20,。 (此总数表示与该帐户关联的用户数。) 任何想法如何实现这一目标? 如果需要更多详细信息,请告诉我。

由于

0 个答案:

没有答案