Worklight JsonStore高级查找

时间:2014-07-28 07:18:42

标签: ibm-mobilefirst jsonstore

如何使用QueryPart在worklight JSONStore中使用高级查找?

我已经尝试了以下代码,但它无法正常工作,我怀疑我是否正确调用了advancedFind。

var query = WL.JSONStore.QueryPart().equal('age', 35);
var collectionName = "people";

WL.JSONStore.get(collectionName).find(query).then(function(arrayResults) {
    // if data not present , get the data from DB
    if (arrayResults.length == 0) {
        } else {

            }
}).fail(function(errorObject) {
    alert("fail" + errorObject);
    // handle failure
});

1 个答案:

答案 0 :(得分:2)

您正在调用find()方法。您要调用的是advancedFind()。此外,advancedFind接收一个查询部分数组,而不仅仅是一个查询部分。您的代码应如下所示:

var queryPart = WL.JSONStore.QueryPart().equal('age', 35);
var collectionName = "people";

WL.JSONStore.get(collectionName).advancedFind([queryPart]).then(function(arrayResults) {
     // if data not present , get the data from DB
     if (arrayResults.length == 0) {

     } else {

     }
}).fail(function(errorObject) {
     alert("fail" + errorObject);
     // handle failure
});

供将来参考, here is the API和一些examples on how to use the Javascript JSONStore API.

相关问题