使用 angularjs 填充 jquery 移动设备 table

Populating jquery mobile table with angularjs

我有一个 table 是在图书馆 angular-smart-table 的帮助下使用 angularjs 开发的。这工作正常,但我想要更多功能,所以我想使用 jquery mobile。我遇到的问题是 table 正在与标题一起形成,但我重复的行没有显示任何数据,我的 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;
    }
});

})();

如我所说,带有 headers 列的行显示正常,但实际数据不正确,这让我相信我的 ng-repeat 存在问题。我之前使用的 table 实际上显示的数据基本上是相同的代码,除了我使用的 <table> 标签:st-table="tableRows"(对于智能 table 库)和然后我的重复是:ng-repeat="row in tableRows"。这是我第一次同时使用 angularjsjquery mobile,因此非常感谢任何帮助!

它不会重复,因为您 没有 将 tableRows 附加到控制器实例 @ scope.tableRows,而是在范围内并且您从通过 cont.tableRow.

控制器实例别名

尝试:-

 this.tableRows = [...

Plnkr