[英]backbone.js filter collection using substring
以下問題使我發瘋。
_.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
的子字符串。 我如何搜索並獲得計數? 我嘗試了索引和搜索方法。 請建議。 提前致謝。
_.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 };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.