2014-02-26 53 views
0

我把這個JSON從taffyDB.com(我把它縮短一點對於節省空間)taffyDB JSON樣本

var friends = TAFFY([ 
    {"id":1,"gender":"M","first":"John"}, 
    {"id":2,"gender":"F","first":"Kelly"}, 
    {"id":3,"gender":"M","first":"Jeff"}, 
    {"id":4,"gender":"F","first":"Jennifer"}  
]); 

我試圖用這個JSON與taffyDb

var friends = TAFFY([{ 
    people:[ 
     { "id": 1, "gender": "M", "first": "John" }, 
     { "id": 2, "gender": "F", "first": "Kelly" }, 
     { "id": 3, "gender": "M", "first": "Jeff" }, 
     { "id": 4, "gender": "F", "first": "Jennifer" } 
    ] 
}]); 

但我沒有任何運氣。

比方說,我想利用這個代碼:

// Find John Smith, by Gender and name 
friends({gender: "M", first: "John"}); 

我無法得到它的工作。當我不包括人它的工作原理確定:[...]

我已經試過

friends({people.gender: "M", people.first: "John"}); 

但這並不工作。

任何想法?

回答

0
var friends = TAFFY([ 
    {"id":1,"gender":"M","first":"John"}, 
    {"id":2,"gender":"F","first":"Kelly"}, 
    {"id":3,"gender":"M","first":"Jeff"}, 
    {"id":4,"gender":"F","first":"Jennifer"}  
]); 

// Find all "M" frends, then filter firstname like "John" 
friends({'gender': "M"}).filter({"first": {"like": "John"}}); 

// Ignores case 
friends({'gender': "M"}).filter({"first": {"likenocase": "john"}}) 

// directly filter 
friends(friends({"first": {"like": "John"}}); 


// output: [{"id":1,"gender":"M","first":"John","___id":"T000003R000002","___s":true}]