D
D
Denioo2019-07-16 18:11:02
JavaScript
Denioo, 2019-07-16 18:11:02

How to fix filtering in Angular?

There is a filter with string values:

vm.filteredPartners = ["COMPANY", "BRANCH", "PERSON"];

In the Angular controller, I write filtering on clicking on which the list should be filtered:
vm.properties = [
      { title: "Юр. лицо", value: PartnersTypeConstants.Properties.COMPANY, isSelected: false },
      { title: "Обособленное подразделение", value: PartnersTypeConstants.Properties.BRANCH, isSelected: false },
          { title: "Физ. лицо", value: PartnersTypeConstants.Properties.PERSON, isSelected: false }
        ];

The error is in the function itself, because it turns out that the function does not return the selected value:
function setPropertyShortName(propertySelection) {
      //vm.selectedValue = !propertySelection.isSelected ? propertySelection.value : undefined;
          for (var i = 0; i < vm.properties.length; i++) {
        if (vm.properties[i].value === vm.filteredPartners.value) {
          vm.properties[i].isSelected = propertySelection.isSelected;
          

              continue;
            }
        
            vm.properties[i].isSelected = false;
      }
      
          search(true);
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denioo, 2019-07-17
@Denioo

vm.properties = [
      { title: "ЮЛ", value: PartnersTypeConstants.Properties.COMPANY, isSelected: false },
      { title: "ОП", value: PartnersTypeConstants.Properties.BRANCH, isSelected: false },
          { title: "ФЛ", value: PartnersTypeConstants.Properties.PERSON, isSelected: false }
        ];

    vm.selectedValue = [];
    //vm.filter.partnerTypes = vm.filteredPartners;
    
    function setPropertyShortName(propertySelection) {
      vm.filteredPartners = propertySelection.isSelected ? propertySelection.value : undefined;
      for (var i = 0; i < vm.properties.length; i++) {
        if (vm.properties[i].value === propertySelection.value) {
          vm.properties[i].isSelected = propertySelection.isSelected;
          //continue;
        }
      }
          search(true);
        }

S
Stalker_RED, 2019-07-16
@Stalker_RED

it turns out that the function does not return the selected value

not surprising, because there is no return in it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question