【发布时间】:2017-02-06 16:41:55
【问题描述】:
我只是不明白这一点。在the smart-table web page 上,它讨论了stSafeSrc
属性,我看不到$scope. displayedCollection 的声明位置。
文字上写着smart-table first creates a safe copy of your displayed collection,而我
我曾假设一个 smart-table 指令正在声明它,但示例代码对我不起作用 - 表格行是空的 - 这就是我认为的问题。
例如,如果我们查看接受的this question 的答案,我们会看到用户将$scope.displayedCollection 声明为一个空数组,并在收到AJAX 响应时为其分配一个值。但是,文档没有提到这一点。
<table st-table="displayedCollection" st-safe-src="rowCollection">
<thead>
<tr>
<th st-sort="firstName">First Name</th>
<th st-sort="lastName">Last Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in displayedCollection">
<td>{{row.firstName}}</td>
<td>{{row.lastName}}</td>
</tr>
</tbody>
</table
app.controller('Ctrl', function($scope, service) {
$scope.displayedCollection = [];
service.all.then(function(list) {
$scope.rowCollection = list;
$scope.displayedCollection = list;
});
});
那么,我需要自己照顾副本吗?文档是否需要更新?演示如何工作?
[更新] 我在 @tufan-yoc 的 the github issues 上找到了这个
您必须将数据数组复制到范围内的其他变量:
st-table="displayedCollection" st-safe-src="rowCollection"
和
//copy the references (you could clone ie angular.copy
// but then have to go through a dirty checking for the matches)
$scope.displayedCollection = [].concat($scope.rowCollection);
如果这确实是一项要求,为什么没有明确记录?
为什么智能表网站上的示例没有它也能工作?
【问题讨论】:
标签: angularjs smart-table