![](/img/trans.png)
[英]Does the JSONStore data/documents from Worklight persist on device (iPhone/Android) even after deleting the App?
[英]Unable to use JSONStore even after I added it
我正在使用MF 6.3.0.00.20150204-0610並使用混合應用程序。 我在應用程序中添加了JSONStore,可以在applicaiton-descriptor.xml中清楚地看到它。 但是,當我嘗試使用該功能時:
def = WL.JSONStore.init("people").done(function() {
console.log("Ok, I think I did the store?");
});
我在控制台中收到此錯誤:
錯誤:無法調用WL.JSONStore.init,因為應用程序中缺少JSONStore。 將JSONStore添加到應用程序描述符,重建並部署它。
我現在肯定已經重建和部署 - 多次。
這是我所做的,然后通過成功消息獲取警報:
共同的\\ js \\ main.js:
var def; function wlCommonInit(){ def = WL.JSONStore.init("people").done(function() { alert("store created"); }); }
右鍵單擊iphone文件夾,然后選擇Run As> Xcode project
我想問題應該是 - 你是如何初始化JSONStore的?
我剛剛嘗試使用MFP CLI並使其正常工作。 這是我的個人設置:
在終端上
$ javac -version
javac 1.7.0_72
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home
$ mfp -v
6.3.0.00.20150204-0610
$ mfp create MFPJSONSTORE
A MobileFirst Project was successfully created at /Users/mfpuser/foo/mfp/6.3/MFPJSONSTORE
$ cd MFPJSONSTORE/
$ mfp add hybrid
[?] What do you want to name your MobileFirst App? myapp
A new Hybrid App was added at /Users/mfpuser/foo/mfp/6.3/MFPJSONSTORE/apps/myapp
$ mfp add environment
[?] What environments you want to add to the hybrid app? iPhone
A new iphone Environment was added at /Users/mfpuser/foo/mfp/6.3/MFPJSONSTORE/apps/myapp/iphone
$ mfp start
Cannot find the server configuration. Creating a new MobileFirst test server.
Initializing MobileFirst Console.
objc[779]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Starting server worklight.
Server worklight started with process ID 778.
$ cd apps/myapp
$ mfp add feature
[?] What feature you want to install in this application? NOTE: Features you have already installed are not shown: JSONStore
A new jsonstore Feature was added at /Users/mfpuser/foo/mfp/6.3/MFPJSONSTORE/apps/myapp
$ git status
On branch master
Changes not staged for commit:
modified: application-descriptor.xml
$ git commit -am "added feature jsonstore"
$ mfp build
App myapp was successfully built.
$ git status
On branch master
Changes not staged for commit:
modified: iphone/native/www/default/filelist
modified: iphone/native/www/default/index.html
modified: iphone/native/www/default/worklight/checksum.js
modified: ../../bin/myapp-all.wlapp
modified: ../../bin/myapp-common.wlapp
modified: ../../bin/myapp-iphone-1.0.wlapp
Untracked files:
iphone/native/www/default/worklight/jsonstore.js
$ git add iphone/
$ git status
On branch master
Changes to be committed:
modified: iphone/native/www/default/filelist
modified: iphone/native/www/default/index.html
modified: iphone/native/www/default/worklight/checksum.js
new file: iphone/native/www/default/worklight/jsonstore.js
Changes not staged for commit:
modified: ../../bin/myapp-all.wlapp
modified: ../../bin/myapp-common.wlapp
modified: ../../bin/myapp-iphone-1.0.wlapp
$ git commit -am "after mfp build with jsonstore"
$ mfp deploy
App myapp was successfully deployed.
$ git status
On branch master
nothing to commit, working directory clean
通用/ JS / main.js:
function wlCommonInit(){
WL.JSONStore.destroy()
.then(function () {
var collections = {
people : {
searchFields: {name: 'string', age: 'integer'}
}
};
return WL.JSONStore.init(collections);
})
.then(function () {
var data = [{name: 'carlos', age: 20},
{name: 'mike', age: 30}];
return WL.JSONStore.get('people').add(data);
})
.then(function () {
return WL.JSONStore.get('people').findAll();
})
.then(function (res) {
console.log("result from prople findAll:");
var resultdiv = document.createElement("div");
var resultsJson = JSON.stringify(res);
resultdiv.innerText = resultsJson;
document.body.appendChild(resultdiv);
console.log(resultsJson)
})
.fail(function (err) {
ok(false, 'Got failure: ' + err.toString());
start();
});
}
在終端上
$ mfp bd
打開XCode
$ open iphone/native/MFPJSONSTOREMyappIphone.xcodeproj
運行應用程序(即iOS模擬器iPhone 6)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.