AngularJS smart-table strange behavior with nested objects and st-search

后端 未结 2 1267
时光说笑
时光说笑 2021-01-13 08:39

I\'m trying to implement the Smart Table module in my AngularJS app. I\'d prefer this over some others mainly because the others seemed require a lot of boilerplate code in

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 09:27

    As laurent said, you need to use a custom filter

    Use st-set-filter to set your filter

    In your module, define a custom filter

    angular.module('myModule').filter('customFilter', ['$parse', function($parse) {
        return function(items, filters) {
            var itemsLeft = items.slice();
    
            Object.keys(filters).forEach(function(model) {
                var value = filters[model],
                    getter = $parse(model);
    
                itemsLeft = itemsLeft.filter(function(item) {
                    return getter(item) === value;
                });
            });
    
            return itemsLeft;
        };
    }])
    

    提交回复
    热议问题