Reputation: 1
The following problem is driving me crazy.
_.each(collection, function( account, key ){
var totalPhy = that.physicianCollection.where({ 'Hospital_Id__c' : account.Id }).length;
account.physicians = { 'total' : totalPhy };
});
It is working when Hospital_Id__c
same as account.Id. But my account Id is a sub string of the hospital_Id__c
. How do I search and get the count? I tried index of and search methods. Pls suggest. Thanks in advance.
Upvotes: 0
Views: 354
Reputation: 2427
_.where
is a simple use case of _.filter
to match exact properties. In your case you will need to actually use _.filter
and write the logic yourself. I'm not sure what the account id / hospital id look like, but the code will probably look something like :
var totalPhy = that.physicianCollection.filter(function(phys, index, collection){
//phys is your model
return phys.get('Hospital_Id__c').indexOf(account.Id) != -1;
//(or however the ids are set, your logic here)
}).length;
account.physicians = { 'total' : totalPhy };
http://underscorejs.org/#filter
Upvotes: 1