我尝试使用smart Tabl e 远程数据,但我没有得到任何输出。我一直在阅读文档,指出在 ajax 数据上应该使用 stSafeSrc 属性,但显然我做错了。
我的标记如下所示
<div class="content">
<div class="container">
{% verbatim %}
{{ rowCollection }}
<button type="button" ng-click="addRandomItem(row)" class="btn btn-sm btn-success">
<i class="glyphicon glyphicon-plus"></i> Add Feed
</button>
<table st-table="displayedCollection" st-safe-src="rowCollection" class="table table-striped">
<thead>
<tr>
<th>Feed Name</th>
<th>parsed Items</th>
<th>Feed Link</th>
<th>Feed Type</th>
<th>Import</th>
<th>Categorize</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in displayedCollection">
<td>{{row.feed_type}}</td>
<td>{{ row.id }}</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
{% endverbatim %}
</div>
</div>
Controller
october.controllers['dashboard/feeds'] = function ($scope, $filter , $request) {
$.request('onFeeds', {success: function(data, scope){
this.success(data).done(function() {
$scope.rowCollection = [];
$scope.rowCollection = angular.fromJson(data.result);
$scope.displayedCollection = [].concat($scope.rowCollection);
console.log($scope.rowCollection); // Array of Objects is present
});
}
});
}
最佳答案
从外观上看,你正在使用这个
https://github.com/responsiv/angular-plugin
您的 Controller 代码错误。您正在调用 $.request()
而不是 $request()
,这是他们的 $request
服务实际上代理 http 请求的地方。这就是它似乎有效的原因。但你实际上并没有通过他们的服务发出 http 请求 - 这将在 Angular 内部 - 你是通过他们使用的第三方库在 Angular 之外发出请求。
您需要将 Controller 更改为以下内容:
october.controllers['dashboard/feeds'] = function ($scope, $filter , $request) {
$request('onFeeds', {success: function(data, scope){
this.success(data).done(function() {
$scope.rowCollection = [];
$scope.rowCollection = angular.fromJson(data.result);
$scope.displayedCollection = [].concat($scope.rowCollection);
console.log($scope.rowCollection); // Array of Objects is present
});
}
});
}
然后他们的 $request
服务将调用 $rootScope.$apply()
- 请参阅第 110 行,
https://github.com/responsiv/angular-plugin/blob/master/assets/js/angular-bridge.js
关于angularjs - 带有 Ajax 数据的 Angular 智能表不会输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27607413/