带有 Ajax 数据的角度智能表不会输出



我尝试在远程数据上使用智能表,但我没有得到任何输出。我一直在文档中读到在 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>

控制器

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

你的控制器代码是错误的。您正在调用$.request()而不是$request(),这是他们的$request服务实际上代理http请求的内容。这就是为什么它似乎正在工作。但是你实际上并没有通过他们的服务发出http请求 - 这将是在angular内部 - 你是在angular之外,通过他们使用的第三方库。

您需要将控制器更改为以下内容:

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

最新更新