Я пытаюсь создать JSONStore в гибридном приложении Mobilefirst 7.0. Проблема, с которой я сталкиваюсь, заключается в том, чтобы обнаружить, что JSONStore уже присутствует в последующих запусках приложения. В документации указано, что вы должны вызвать WL.JSONStore.init (...) перед вызовом WL.JSONStore.get (...).Как получить уже созданный JSONStore в Mobilefirst
Итак, вопрос заключается в последующих запусках приложения (что означает, что приложение запускается в первый раз и успешно создано JSONStore), и это новый прогон, каков правильный способ проверить, существует ли уже JSONStore?
Если мне нужно снова вызвать init, как мне это сделать, не уничтожая то, что там?
настоящее время я использую этот фрагмент кода, чтобы обнаружить ...
function checkJSONStore() {
alert("In checkJSONStore");
var collectionName;
try {
// Check to see if JSONStore exists...
collectionName = WL.JSONStore.get('appStore');
} catch (e) {
// TODO: handle exception
alert("checkJSONStore: Exception = " + e.message);
}
alert("Returning from checkJSONStore: " + collectionName);
return collectionName;
}
Вот код, который создает магазин ... он работает успешно.
function initJSONStore() {
console.log("In initJSONStore:");
var collectionName = "appStore";
var Data = {
item: 'newinstall',
value: 1
};
var JSONStoreCollections = {};
JSONStoreCollections[collectionName] = {};
JSONStoreCollections[collectionName].searchFields = {item: 'string'};
try {
console.log("Destroy any collections before we start");
WL.JSONStore.destroy().then(function() {
//handle success
console.log("initJSONStore: JSONStore destroy success");
})
.fail(function (error) {
//handle failure
console.log("initJSONStore: JSONStore destroy failure: " + error);
});
console.log("Calling WL.JSONStore.init");
WL.JSONStore.init(JSONStoreCollections).then(function() {
console.log("initJSONStore: JSONStore init success");
WL.JSONStore.get('appStore').add(Data).then(function() {
console.log("initJSONStore: JSONStore add success");
}).fail(function (error) {
console.log("initJSONStore: JSONStore add failure: " + error);
});
}).fail(function (error) {
console.log("initJSONStore: JSONStore init failure");
});
} catch (e) {
// TODO: handle exception
//console.log("initJSONStore: Exception = " + e.message);
alert("initJSONStore: Exception = " + e.message);
}
console.log("Exiting initJSONStore:");
}
Итак, что такое синтаксис, чтобы проверить его с помощью init и get? – Tim
Это более обычная реализация, чтобы проверить это. Вы можете увидеть пример в следующем файле. См. Функцию 'onlineAuthenticationSuccess()': https://github.com/MobileFirst-Platform-Developer-Center/OfflineAuthentication/blob/release71/apps/OfflineAuthSample/common/js/main.js –
Идан, вы упомянули «и так в следующем init он будет (повторно) создан. «... не является точкой постоянной коллекции, что объект был сохранен, и я могу просто его извлечь? Если мне нужно каждый раз воссоздавать его ... тогда это не настойчиво ... может быть, это было неправильное предположение с моей стороны? – Tim