javascript - filter array inside object angular -


i'm trying filter results term since it's inside array it's being quite hard reach them filters in angularjs.

var test=[  {  "title": "random stuff",  "path": "/random_stuff.html",  "labels": [    {     "term": "viewed",     "probability": 0.083   },    {     "term": "firefox",     "probability": 0.083   },    {     "term": "cookies",     "probability": 0.083   },    {     "term": "times",     "probability": 0.055   },  ],  } ]; 

html :

<input class="looking" type="text"  ng-model="data.keywords"/> <li ng-repeat="se in searchctrl.data.pages | orderby : '-views' | filter: ??" > 

the data.keywords come here:

var id=$routeparams.teamid; var context=this;  context.data = {     pages:[],     keywords:id,     islogged:false }; 

because need first results showed id in url.

taken angularjs documentation:

friendobj in friends | filter:{$: 'your filter'} 

a pattern object can used filter specific properties on objects contained array

note named property match properties on same level only, while special $ property match properties on same level or deeper.

view expression section: filter documentation

<div ng-controller="myctrl">     <input type="text" data-ng-model="search" />     <ul>     <li data-ng-repeat="page in list.pages | filter: {$: search}">{{page.title}}</li>     </ul> </div>  var myapp = angular.module('myapp', []);  myapp.controller('myctrl', ['$scope', function ($scope) {   $scope.list = {     pages: [{         "title": "random stuff1",             "path": "/random_stuff.html",             "labels": [{             "term": "viewed",                 "probability": 0.083         }, {             "term": "firefox",                 "probability": 0.083         },          {             "term": "cookies",                 "probability": 0.083         }, {             "term": "times",                 "probability": 0.055         }, ],     }, {         "title": "random stuff2",             "path": "/random_stuff.html",             "labels": [{             "term": "viewed",                 "probability": 0.083         }, {             "term": "firefox",                 "probability": 0.083         },          {             "term": "cookies",                 "probability": 0.083         }, {             "term": "my name",                 "probability": 0.078         }, ],     }] }; }]); 

please see working example: https://jsfiddle.net/1j5fnrd6/

type 'my name' , see filter being applied on random stuff2


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -