简体   繁体   中英

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. I added JSONStore to the app and can see it clearly in 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. Add JSONStore to the application descriptor, rebuild and deploy it.

I've definitely rebuilt and deployed now - multiple times.

Here's what I did followed by getting an alert with a sucess message:

  1. Created a new project and application, added the iPhone environment
  2. Added the JSONStore feature (from the Application Descriptor design view)
  3. In common\\js\\main.js:

     var def; function wlCommonInit(){ def = WL.JSONStore.init("people").done(function() { alert("store created"); }); } 
  4. Right-click the iphone folder and select Run As > Xcode project

  5. Run the app in XCode's iOS Simulator
  6. Got the following alert

I suppose the question should be - how did you initialize JSONStore?

在此输入图像描述

I just tried using the MFP CLI and got it working. Here is my personal setup:

  • JDK 1.7 and $JAVA_HOME set (MFP doesn't support 1.8 yet)
  • MFP CLI version 6.3.0.00.20150204-0610 (mfp -v)
  • Using git to show changed files on steps add feature, build, and deploy
  • Using main.js from MFP Tutorial JSONStore – JavaScript API

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:

    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

$ open iphone/native/MFPJSONSTOREMyappIphone.xcodeproj

Run App (ie iOS Simulator iPhone 6)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM