0

我从 taffyDB.com 获取了这个 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"});

但这也不起作用。

有任何想法吗?

4

1 回答 1

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}] 
于 2015-02-10T08:23:44.390 回答