我正在使用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添加到应用程序描述符,重建并部署它。
我现在已经多次重建和部署 - 多次。
答案 0 :(得分:0)
这是我做了什么,然后通过成功消息获得提醒:
共同的\ js \ main.js:
var def;
function wlCommonInit(){
def = WL.JSONStore.init("people").done(function() {
alert("store created");
});
}
右键单击iphone文件夹,然后选择Run As> Xcode项目
我想问题应该是 - 你是如何初始化JSONStore的?
答案 1 :(得分:0)
我刚尝试使用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)