这是我的tableParams代码:
$scope.tableParams = new ngTableParams({
page: 1,
count: 10,
sorting: {
lastRun: 'desc'
}
},
{
debugMode: true,
total: $scope.completedQueries.length,
getData: function($defer, params) {
var orderedData = params.sorting() ?
$filter('orderBy')($scope.completedQueries, params.orderBy()) :
data;
orderedData = $filter('filterFailed')(orderedData, $scope.showOnlyFailed);
orderedData = $filter('filterMatchingKeys')(orderedData, $scope.keysFilter);
params.total(orderedData.length);
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(),
params.page() * params.count()));
}
});
请注意,我使用过这个ngTable不使用"$ data"列表,只是遍历我的"completedQueries"列表.当它像这样工作时,当我点击"仅显示失败的查询"复选框或在"keysFilter"输入字段中输入文本时,列表会立即更改.
但是,现在我正在使用"$ data"列表,当我更改其中任何一个字段时没有任何反应.事实上,我甚至为这两个领域添加了$ watch-es,而且他们都没有开火.但是,当我对这两个字段中的任何一个进行更改时,我知道正在重新评估表数据,因为其中两列的数据预计为millis值,并且我在这些列上有一个自定义过滤器,用于将值转换为一个"很久以前"的英语表达,比如"30秒前"或"2分钟前",每当我更改其中一个输入字段时,我看到表中的那些表达式发生了变化,但它仍然没有适当的过滤.
如果重要的话,这里是我添加到我的范围的$ watch-es.这些从未出现过:
$scope.$watch("showOnlyFailed", function() {
$scope.tableParams.reload();
});
$scope.$watch("keysFilter", function() {
$scope.tableParams.reload();
});
请注意,当我有这些注释时,我在看到"getData()"方法后看到以下错误:
Error: settings.$scope is null
@http://localhost:8000/js/diag/libs/ng-table.src.js:411
qFactory/defer/deferred.promise.then/wrappedCallback@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:11046
qFactory/ref/<.then/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:11132
Scope.prototype.$eval@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:12075
Scope.prototype.$digest@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:11903
Scope.prototype.$apply@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:12179
bootstrap/doBootstrap/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:1341
invoke@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:3762
bootstrap/doBootstrap@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:1340
bootstrap@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:1353
angularInit@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:1301
@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js:21048
n.Callbacks/j@http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js:2
n.Callbacks/k.fireWith@http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js:2
.ready@http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js:2
K@http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js:2
http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js
Line 9509
这是相关的代码块:
$defer.promise.then(function (data) {
settings.$loading = false;
log('ngTable: current scope', settings.$scope);
if (settings.groupBy) {
self.data = settings.$scope.$groups = data;
} else {
self.data = settings.$scope.$data = data; // line 411
}
settings.$scope.pages = self.generatePagesArray(self.page(), self.total(), self.count());
});
更新:
这是我的plunkr,它表明更改外部过滤器字段不起作用.我还有两个$ watch-es评论出来试图纠正这个问题.当我评论这些时,我在ng-table中得到一个错误,抱怨null范围.
更新:
我尝试将"newvalue,oldvalue"参数添加到我的$ watch-es(我更新了plunkr).现在,对字段的更改会导致表更新.不幸的是,我仍然在ng-table的第411行获得了堆栈跟踪.
1> cleftheris..:
您不需要手表,也不需要您创建的自定义过滤器.实际上,角度的'过滤器'过滤器功能非常强大.
您只需创建一个对象,使用与您的项目字段匹配的成员来跟踪您的过滤器值.像这样的东西.
$scope.filter = {
key: undefined,
failed: undefined
}
那么你可以getData
使用回调内部params.filter()
.我在这里更新了你的plunker.您还可以查看以下示例:
var app = angular.module('main', ['ngTable']);
app.controller('MainCtrl', function($scope, $http, $filter, ngTableParams) {
$scope.completedQueries = [{"key":"abc000","lastRun":123,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc001","lastRun":1234,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc002","lastRun":111111111,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":true},{"key":"abc003","lastRun":123,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc004","lastRun":1234,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":true},{"key":"abc005","lastRun":111111111,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc006","lastRun":123,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc007","lastRun":1234,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc008","lastRun":111111111,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc009","lastRun":123,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc010","lastRun":1234,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc011","lastRun":111111111,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc012","lastRun":123,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":true},{"key":"abc013","lastRun":1234,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc014","lastRun":111111111,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc015","lastRun":123,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":true},{"key":"abc016","lastRun":1234,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false},{"key":"abc017","lastRun":111111111,"lastSuccessfulTime":9999,"elapsedTime":456,"rows":10,"failed":false}];
$scope.filter = {
key: undefined,
failed: undefined
};
$scope.tableParams = new ngTableParams({
page: 1,
count: 10,
filter: $scope.filter
}, {
debugMode: true,
total: $scope.completedQueries.length,
getData: function($defer, params) {
var orderedData = params.sorting() ? $filter('orderBy')($scope.completedQueries, params.orderBy()) : data;
orderedData = $filter('filter')(orderedData, params.filter());
params.total(orderedData.length);
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
{{queryInfo.key}} |
{{queryInfo.lastRun}} |
{{queryInfo.lastSuccessfulRun}} |
{{queryInfo.elapsedTime}} ms |
{{queryInfo.rows}} |
{{queryInfo.failed}} |
|
推荐阅读
-
如何解决《使用API19+以较短的间隔更新Widget》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《尝试从apache的sharedRDD中检索数据点燃上下文》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《Spark调用ShuffleBlockFetcherIterator时发生了什么?》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《如何在AWSElasticBeanstalk上安装/运行SparkJavaFramework?》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《当用户单击另一个DOM元素时停止setInterval计时器》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《运行Blanket.js》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《ApacheNutch工作器实例的最大数量》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《如何在OSX中测量L1,L2,L3缓存命中和未命中》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《在资产目录中使用字体图标》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《将字符串转换为float而不会丢失精度》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《SVM和铰链损耗之间的关系是什么?》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《在R中从一个表中删除一个表》经验,为你挑选了2个好方法。 ...
[详细]
-
如何解决《无法在JavaScript中为已创建的DOM元素设置ID属性》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《Python在纪元时间增加了几天》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《如何优雅地处理Ajax调用的登录过期?》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《如何将HTMLUI中的多个输入添加到Google电子表格中?》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《应用程序在访问类中的第一个静态变量时崩溃》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《无需使用for语句即可在golang数组/切片上进行迭代》经验,为你挑选了1个好方法。 ...
[详细]
-
如何解决《如何在ASP.NETmvc6中指定多态类型》经验,为你挑选了0个好方法。 ...
[详细]
-
如何解决《Python-使用defaultdict制作自定义对象的字典》经验,为你挑选了1个好方法。 ...
[详细]