angularJS:动态标题排序不起作用
angularJS: Dynamic header sorting not working
我正在尝试实现一种解决方案,通过使用AngularJS点击表的标题来对表进行排序。
我在谷歌搜索后发现了一个很好的例子:https://scotch.io/tutorials/sort-and-filter-a-table-using-angular
我可以看到向上和向下箭头,但当我单击它们时,表不会排序。
我认为问题在于在我的情况下如何格式化JSON对象。我一直没能弄清楚,我希望通过我在这篇帖子中提供的信息,我能得到一些帮助,了解我做错了什么。
这是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);
我开始工作了,最终版本:https://jsfiddle.net/itortu/nhhppf53/
非常感谢。
您正在使用控制器的
ng-controller="Company:OpportunityController as opportunity"
因此,你必须在你的点击中引用sortType和sortReverse,就像这样:
ng-click="opportunity.sortType = 'Products'; opportunity.sortReverse = !opportunity.sortReverse"
相关文章:
- jquery中DataTables插件中的排序不起作用
- j查询排序不起作用
- 为什么这种 jquery 驱动的表排序不起作用
- jQuery DataTables排序不起作用
- populate中的Mongoose排序不起作用
- 使用J-query数据表,美国日期格式的自定义排序不起作用
- jQuery 表排序器排序不起作用
- 从 AJAX 调用的 PHP 对数组进行排序不起作用
- Jquery UI 可排序不起作用
- 基于CSS类和文本对元素进行排序不起作用
- 使用嵌套json时,ngTable中的排序不起作用
- js文档排序不起作用
- jQueryDataTables-当日期也是一个链接时,排序不起作用
- angularJS:动态标题排序不起作用
- ng表排序不起作用
- 淘汰排序不起作用
- SlickGrid:重新排序后的排序不起作用
- 数据表排序不起作用
- 数组排序不起作用
- jqgrid:动态添加记录后排序不起作用