0

I have data sets for class, batch and users. The user data set contains name,email,class and batch. Class and batch contains list of classes and batches. I want to do search in the user data set using name,email,batch and class. Name and username is provided inside same text field while class in one select option and batch in another select option,all these input fields are defined inside an object and this object is given as filter in ng-repeat.

This is my js

     this.autorun(() => {

            $scope.dataSet = Meteor.users.find({}).fetch()
            $scope.searchFilter = [{
                "name": "Class",
                "data": self.classe,
                "enabled": true,
                "label": "class"
            }, {
                "name": "Batch",
                "data": self.batchs,
                 "label": "batch"
            }]
            $scope.filterObj = {}
            i = 0
            _.each($scope.searchFilter, function(filter){
                if(!$scope.search){
                    $scope.search = []
                }
                    $scope.filterObj[filter.label] = $scope.search[i]
                    i++
            })
            //$scope.filterObj['name'] = $scope.word

and this is my html

 <md-card flex="30" flex-xs="100" flex-sm="45" flex-gt-xs="30" layout-wrap ng-repeat="names in dataSet|filter:filterObj" class="cardfilter textWrap">
                    <div layout="row">
                        <div class="md-media-sm card-media"><img src="images/icons/student_profile.png" class="imageFilter"></div>
                        <div>
                            <p class="searchBold">{{names.name}}--{{names.class}}--{{names.batch}}
                            </p>
                            <p class="searchColor">{{names.username}}</p>
                            <p></p>
                        </div>

Can somebody figure out what is wrong with my code?

Aysha Azura
  • 179
  • 1
  • 2
  • 15
  • Think the problem is you are setting up the filterObj one time but the $scope.search is not set at that point and from what's shown I'm just assuming this doesn't get updated when the $scope.search changes. Would be good to have a clear here's what I expect and here's what happens at the end. Also to find the issue yourself you can try using `debugger;` to add a breakpoint through the code or use the sources panel in the debug panel and hit ctrl+p in there to find a file and add breakpoints to step through it. – shaunhusain May 24 '16 at 05:38
  • @shaunhusain can you elaborate!! Can you clear out where my code is failing – Aysha Azura May 24 '16 at 05:41
  • http://stackoverflow.com/questions/19460046/how-to-debug-the-js-in-jsfiddle/19460060#19460060 <-- I have a quick answer here and there's a little more detailed one below it on going to the sources panel. This will allow you to set break points, so the code execution will stop and you can look at the state of variables and step line by line through the code. More details here too https://developer.chrome.com/devtools/docs/javascript-debugging – shaunhusain May 24 '16 at 05:45
  • Regarding your particular problem here, would need to see where the $scope.search is meant to be populated but my guess is that the autorun is only executed once but you're expecting this to "live filter" so you want it to maybe be bound to a function that returns the filterObj or otherwise would need a $watch to know when the search object has changed. – shaunhusain May 24 '16 at 05:46
  • any changes in the input filed should be done in $scope.search and I have provided autorun to make my code reactive. – Aysha Azura May 24 '16 at 06:01

0 Answers0