0

I'm having json as below

  var content = [{
  "DocList": [
   {
  "Events": [
    {
      "CategoryName": "PressStatements",
      "DisplayName": "Press Statements",
      "ID": 9
    },
    {
      "CategoryName": "Reports",
      "DisplayName": "Reports",
      "ID": 10
    }
  ],
  "Heading": "News 2",
  "PageID": 23,
   "Date": "\/Date(1454537792000)\/"

},
{
  "Events": [
    {
      "CategoryName": "Research",
      "DisplayName": "Research",
      "ID": 6
    }
  ],
  "Heading": "Heading",
  "PageID": 20,
  "Date": "\/Date(1437417792000)\/"
}
]}
];


$scope.data=content;

 $scope.filterItems = function(g) {
//console.log('filterItems is run');
var ret = $filter('filter')(g.NewsList,"");
//g.filteredItemCount = ret.length
return ret
 };

 $scope.abms = [];


 //Options Inside Select tag
angular.forEach(news[0].NewsList, function(newsItems, index) {
  angular.forEach(newsItems.CategoryList, function(category, index){
    $scope.abms.push(category.DisplayName);
  });
});

i'm displaying Events in select option depending upon that i have to display the data, for selection i'm using select tag with ng-model

<select ng-model="selected"><option ng-repeat="item1 in abms" >{{item1}}</option></select>
   <div id="dataRow{{$index}}" ng-repeat="item1 in (filtered = filterItems(d)) | findobj:selected">

  //display data depending on option selection

  </div>

If i select any categoryName from Events[0] then it should display data from DocList[0] data and same to other for select option.

//filter - dont knw this the way to do it

myapp.filter('findobj', function() {
  return function(dataobj, selected) {
  return dataobj.filter(function(news) {
  //alert('got something');
    return (selected || []).some(function(s) {
    alert('got something');
    return news.CategoryList.CategoryName === s.CategoryList.CategoryName;
    });
   });
 };
});

How to achieve that?

Thanks in Advance...

7
  • what is findobj filter? it custom filter? can you provide working sample on jsfiddle or plunkr? Commented Jul 9, 2015 at 13:10
  • @Grundy im trying to implement findobj filter Commented Jul 9, 2015 at 13:12
  • add this to your post also :-) Commented Jul 9, 2015 at 13:14
  • @Grundy its not working or may be wrong way to do..dont knw ;-) Commented Jul 9, 2015 at 13:15
  • 1
    Let us continue this discussion in chat. Commented Jul 9, 2015 at 13:27

1 Answer 1

1

you need fix your findobj filter something like this

myapp.filter('findobj', function () {
    return function (dataobj, selected) {
        if (!selected) return dataobj;//if nothing selected - return initial array
        return dataobj.filter(function (news) {
            //select only news where in category list places selected category
            return news.CategoryList.some(function (category) {
                //check display category name
                return category.DisplayName === selected;
            });
        });
    };
});

working sample on JSFIDDLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.