以下问题让我发疯。
_.each(collection, function( account, key ){
var totalPhy = that.physicianCollection.where({ 'Hospital_Id__c' : account.Id }).length;
account.physicians = { 'total' : totalPhy };
});
当Hospital_Id__c
与account.Id相同时,它正在工作。但我的帐号ID是hospital_Id__c
的子字符串。我如何搜索并获得计数?我试过索引和搜索方法。请建议。提前谢谢。
答案 0 :(得分:1)
_.where
是_.filter
的简单用例,用于匹配确切的属性。在您的情况下,您需要实际使用_.filter
并自己编写逻辑。我不确定帐户ID /医院ID是什么样的,但代码可能看起来像:
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 };