使用angularjs填充jquery移动表

时间:2015-01-19 16:04:35

标签: javascript jquery angularjs jquery-mobile

我有一张表,它是在图书馆的帮助下使用angularjs开发的:angular-smart-table。这工作正常,但我想要更多功能,所以我想使用jquery mobile。我遇到的问题是表格正在形成标题,但我重复的行不显示任何数据,我的js调试没有显示任何错误。这是我的代码:

HTML:

<body ng-controller="MyMainController as cont">
    <section ng-controller="PanelController as panel">
        <span>
            *span items*
        </span>
        <div class="panel" ng-show="panel.isSelected(1)">
            <table data-role="table" id="table-custom-2" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="b" data-column-btn-text="Columns" data-column-popup-theme="a">
                <thead>
                    <tr class="ui-bar-d">
                        <th></th>
                        <th data-priority="1" st-sort="account">Account #</th>
                        <th st-sort="name">Campaign Name</th>
                        <th data-priority="4">Comments</th>
                        <th data-priority="2" st-sort="priority">Priority</th>
                        <th data-priority="2" st-sort="zipCode">Zip Code</th>
                        <th data-priority="2" st-sort="address">Address</th>
                        <th data-priority="2" st-sort="status">Status</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="row in cont.tableRows">
                        <td>{{row.checked}}</td>
                        <td>{{row.account}}</td>
                        <td>{{row.name}}</td>
                        <td>{{row.comments}}</td>
                        <td>{{row.priority}}</td>
                        <td>{{row.zipCode}}</td>
                        <td>{{row.address}}</td>
                        <td>{{row.status}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="panel" ng-show="panel.isSelected(2)" id="map-canvas">
            Map
        </div>
    </section>
    *my javascript tags*
</body>

JS:

(function(){
var myVar = angular.module('cont', []);

myVar.controller('MyMainController', ['$scope', '$filter', function (scope, filter){
    scope.tableRows = [
    {
        checked: false,
        account: 1,
        name: "Name1",
        comments: "Comments`",
        priority: "High",
        zipCode: 11111,
        address: "Address",
        status: "Active"  
    },
    {
        checked: true,
        account: 2,
        name: "Name2",
        comments: "Comments2",
        priority: "Medium",
        zipCode: 22222,
        address: "Address2",
        status: "Active" 
    },
    {
        checked: false,
        account: 3,
        name: "Name3",
        comments: "Comments3",
        priority: "Low",
        zipCode: 33333,
        address: "Address3",
        status: "Active" 
    },
    {
        checked: false,
        account: 4,
        name: "Name4",
        comments: "",
        priority: "Low",
        zipCode: 44444,
        address: "Address4",
        status: "Active" 
    }];
}]);

leadPlanning.controller('PanelController', function(){
    this.tab = 1;
    this.selectTab = function(setTab) {
        this.tab = setTab;
    }
    this.isSelected = function(checkTab) {
        return this.tab === checkTab;
    }
});

})();

正如我所说,带有列标题的行显示正常,但实际数据并没有让我相信我的ng-repeat存在问题。我之前拥有的表实际显示的数据基本上是相同的代码,除了<table>标签我有st-table="tableRows"(对于智能表库)然后我的重复是:{{1 }}。这是我第一次使用ng-repeat="row in tableRows"angularjs,所以我们非常感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

它没有重复,因为你有将tableRows附加到控制器实例@ scope.tableRows,而是它在范围内,你从控制器实例别名中引用它cont.tableRow

尝试: -

 this.tableRows = [...

<强> Plnkr