[英]angularJS: Dynamic header sorting not working
I am trying to implement a solution to sort a table by clicking its headers, using AngularJS. 我正在尝试使用AngularJS通过单击表头来实现对表进行排序的解决方案。
I found a good example after doing a Google search: https://scotch.io/tutorials/sort-and-filter-a-table-using-angular 经过Google搜索后,我发现了一个很好的例子: https : //scotch.io/tutorials/sort-and-filter-a-table-using-angular
I am able to see the up and down arrows, but the table does not sort when I click them. 我能够看到向上和向下箭头,但是单击它们时表格未排序。
I think the problem resides in how the JSON object is formatted in my situation. 我认为问题出在我的情况下如何格式化JSON对象。 I have not been able to figure it out, and I am hoping that with the information that I am providing on this post, I can get some help to understand what I am doing incorrectly.
我还无法弄清楚,我希望借助本文提供的信息,我可以得到一些帮助,以了解我在做错什么。
Here is a copy of the JavaScript: 这是JavaScript的副本:
(function (define, angular) {
'use strict';
define(function () {
var opportunityController = function ($scope, Metadata, Factory) {
var vm = this;
//set the default sort type
vm.sortType = 'Products';
//set the default sort order
vm.sortReverse = false;
Factory.Data(caller.sp, caller.filter).then(function (payload) {
var data = angular.fromJson(payload.data).Table;
ProcessData(data);
});
function ProcessData(data) {
if (angular.isDefined(data)) {
var counter = 0;
vm.products = [];
vm.productsSet = FindByAsObjectArray(function (x) {
return (x.TypeName == "Product");
}, data);
for (var index = 0, length = vm.productsSet.length; index < length; index++) {
vm.products[index] = {
data: vm.productsSet[index]
};
}
}
}
};
return ['$scope','Metadata','Factory',opportunityController];
});
})(define, angular);
I got it to work, final version: https://jsfiddle.net/itortu/nhhppf53/ 我知道了,最终版本: https : //jsfiddle.net/itortu/nhhppf53/
Many thanks. 非常感谢。
You are using controllerAs 您正在使用controllerAs
ng-controller="Company:OpportunityController as opportunity"
therefor you have to reference sortType and sortReverse in your ng-click like so: 因此,您必须在ng-click中引用sortType和sortReverse,如下所示:
ng-click="opportunity.sortType = 'Products'; opportunity.sortReverse = !opportunity.sortReverse"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.