我有一个仅在库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"
(用于智能表库),然后重复的是:ng-repeat="row in tableRows"
。这是我第一次与angularjs
和jquery mobile
一起工作,因此任何帮助将不胜感激! 最佳答案
它不会重复,因为您尚未将tableRows附加到控制器实例@ scope.tableRows
上,而是在作用域上,并且您正在通过cont.tableRow
从控制器实例别名中引用它。
尝试:-
this.tableRows = [...
Plnkr