[英]Unable to use JSONStore even after I added it
I'm using MF 6.3.0.00.20150204-0610 and working with a hybrid application. 我正在使用MF 6.3.0.00.20150204-0610并使用混合应用程序。 I added JSONStore to the app and can see it clearly in applicaiton-descriptor.xml. 我在应用程序中添加了JSONStore,可以在applicaiton-descriptor.xml中清楚地看到它。 However, when I try to use the feature: 但是,当我尝试使用该功能时:
def = WL.JSONStore.init("people").done(function() {
console.log("Ok, I think I did the store?");
});
I get this error in the console: 我在控制台中收到此错误:
Error: Failed to call WL.JSONStore.init because JSONStore is missing in the application. 错误:无法调用WL.JSONStore.init,因为应用程序中缺少JSONStore。 Add JSONStore to the application descriptor, rebuild and deploy it. 将JSONStore添加到应用程序描述符,重建并部署它。
I've definitely rebuilt and deployed now - multiple times. 我现在肯定已经重建和部署 - 多次。
Here's what I did followed by getting an alert with a sucess message: 这是我所做的,然后通过成功消息获取警报:
In common\\js\\main.js: 共同的\\ js \\ main.js:
var def; function wlCommonInit(){ def = WL.JSONStore.init("people").done(function() { alert("store created"); }); }
Right-click the iphone folder and select Run As > Xcode project 右键单击iphone文件夹,然后选择Run As> Xcode project
I suppose the question should be - how did you initialize JSONStore? 我想问题应该是 - 你是如何初始化JSONStore的?
I just tried using the MFP CLI and got it working. 我刚刚尝试使用MFP CLI并使其正常工作。 Here is my personal setup: 这是我的个人设置:
On Terminal 在终端上
$ 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
common/js/main.js: 通用/ 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();
});
}
On Terminal 在终端上
$ mfp bd
Open XCode 打开XCode
$ open iphone/native/MFPJSONSTOREMyappIphone.xcodeproj
Run App (ie iOS Simulator iPhone 6) 运行应用程序(即iOS模拟器iPhone 6)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.