【发布时间】:2014-08-10 00:27:04
【问题描述】:
我正在尝试存储 $.ajax() 函数返回的 json 数据,但遇到了麻烦。下面是我打的电话(我知道它正确地返回了我的 JSON 数据,我已经记录了它(由于个人原因删除了网址)。
$.ajax({
type: "GET",
url: **url that returns json data**
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
return msg;
},
error: function(e){
WL.Logger.log(e);
}
});
然后我使用 worklight 初始化我的 JSONStore:
//Setup JSON store
var collectionName = 'people';
//Object that defines all the collections
var collections = {};
//Object that defines the 'people' collection
collections[collectionName] = {};
WL.JSONStore.init(collections);
所以现在我遇到了问题。我想将从我的 ajax 调用返回的 JSON 数据添加到我的 JSONStore。所以我尝试了这个(getJSONData 是上面 ajax 调用的包装器):
WL.JSONStore.get(collectionName).add(getJSONData());
但是,当我打印集合时,其中没有存储任何内容,当我打印 WL.JSONStore.get(collectionName).count 时,没有返回任何内容。如何正确添加返回给我的数据?
【问题讨论】:
标签: json ibm-mobilefirst jsonstore