簡體   English   中英

使用子字符串的骨架.js過濾器集合

[英]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 };

http://underscorejs.org/#filter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM