javascript - Angular LoadAsh - filtering records matching by fields on Multiple Objects of different Type -


i've been struggling bit learning loadash , how correctly pull data want more advanced tricks. single objects , lookups pretty simple i'm trying pull array records groupid, if groupid exists in object isn't same.

for example: generic json example of objects, each arrays of records.

groups ..  {     groupid:     name:     code: }  options .. {     groupid:     optionid:     name:     code: } 

the problem i'm having pulling options if groupid exist in groups array in loadash.

i've tried stuff

var results = []; _.foreach(groups, function(g) {     var found _.find(options, g, function(option, group) {          return option.groupid === group.groupid;     })     results.push(found); }); 

i haven't had luck figuring out best way filter these down.

any words if wisdom appreciated, thanks!

something should work,

var result = _.filter(options, function(o) {    return _.filter(groups, function(g) { return g.groupid == o.groupid; }).length > 0; }); 

actually think inner search perform better find, since returns first match, not sure though

var result = _.filter(options, function(o) {    return _.find(groups, { 'groupid': o.groupid }); }); 

hope helps.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -