Ibm mobilefirst 未返回Worklight JSONStore结果

Ibm mobilefirst 未返回Worklight JSONStore结果,ibm-mobilefirst,jsonstore,Ibm Mobilefirst,Jsonstore,我有一个函数,如果JSONStore查询成功,它应该返回JSONStore查询的结果数组。由于某些原因,它不会返回结果 这是我的职责 function getJSON(){ var collectionName = 'messages'; var query = {title: 'asdf'}; var options = { exact: false, limit: 10 }; result = []; WL.JSONStore.get(collecti

我有一个函数,如果JSONStore查询成功,它应该返回JSONStore查询的结果数组。由于某些原因,它不会返回结果

这是我的职责

function getJSON(){
var collectionName = 'messages';
var query = {title: 'asdf'};
var options =  {
        exact:  false,
        limit:  10
};
result = [];

WL.JSONStore.get(collectionName)
.find(query, options)
.then(function (ArrayResult) {
    result = ArrayResult;
    console.log(result);
    console.log(typeof result);
    return result;
})
.fail(function (errrorObject){
    console.log("could not get JSONStore: \n" + errrorObject);
});
}

这就是所谓的:

$("#button").click( function() {
   console.log("type of returned result in buttonClick: " + typeof getJSON());
})
控制台输出也以奇怪的顺序出现:

 "weird orderd output" CDMS_Demo.js:96
 "type of returned result in buttonClick: undefined" CDMS_Demo.html:57
 "result in getJSON: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" CDMS_Demo.js:89
 "type of result in getJSON: object" CDMS_Demo.js:90

有人知道如何修复它了吗?

您似乎希望异步代码能够同步运行。尝试添加回调,一些伪代码:

函数getJSON回调{ var collectionName='messages'; var query={title:'asdf'}; 变量选项={ 准确:错, 限额:10 }; WL.JSONStore.getcollectionName .findquery,选项 .Then函数数组结果{ console.logJSON.stringifyarrayResult; callbackarrayResult; } .failfunction errorObject{ console.logerrorObject.toString; }; } $button.clickfunction{ getJSONfunction arrayResult{ console.logJSON.stringifyarrayResult; }; };
JSONStore是一个异步API,这就是为什么使用它的代码是异步的。请单击答案旁边的绿色复选标记,让其他用户知道这是“已接受的答案”。