使用MobileFirst Platform 7.1在JSONStore中进行CRUD操作 [英] CRUD Operation in JSONStore using MobileFirst Platform 7.1
本文介绍了使用MobileFirst Platform 7.1在JSONStore中进行CRUD操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是MFP的新手,我正在尝试执行基本的CRUD操作。执行以下代码后,没有任何事情发生。如果我能得到一些帮助,我将非常感激。谢谢。
I'm new to MFP and I'm trying to perform a basic CRUD operation. Nothing is happening after the following code is executed. I will highly appreciate if i can get some help. Thank you.
main.js
function wlCommonInit () {
var collections = {
people : {
searchFields: {name: 'string', age: 'integer'}
}
};
WL.JSONStore.init(collections).then(function (collections) {
// handle success - collection.people (people's collection)
}).fail(function (error) {
alert("alert" + error);
// handle failure
});
var collectionName = 'people';
var options = {};
var data = {name: 'yoel', age: 23};
WL.JSONStore.get(collectionName).add(data, options).then(function () {
// handle success
}).fail(function (error) {
// handle failure
});
// to display results using query yoel
var query = {name: 'yoel'};
var collectionName = 'people';
var options = {
exact: false, //default
limit: 10 // returns a maximum of 10 documents, default: return every document
};
WL.JSONStore.get(collectionName).find(query, options).then(function (results) {
// handle success - results (array of documents found)
}).fail(function (error) {
// handle failure
});
}//end wlCommonInit
推荐答案
JSONStore是异步。使用您编写的代码,您无法确定它的运行顺序。
JSONStore is asynchronous. With the code you wrote you cannot be sure of the order it is run.
JavaScript代码很可能会调用你的 add()
或 find( )在你的
init()
发生之前。
The JavaScript code is most likely calling one of your add()
or find()
before your init()
happens.
这篇关于使用MobileFirst Platform 7.1在JSONStore中进行CRUD操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文