2016-04-19 18 views
0

MobileFirst 7.0ハイブリッドアプリケーションでJSONStoreを作成しようとしています。私が抱えている問題は、JSONStoreがその後のアプリケーションの実行時に既に検出されていることを検出できることです。ドキュメントでは、WL.JSONStore.get(...)を呼び出す前にWL.JSONStore.init(...)を呼び出さなければならないと述べています。Mobilefirstで既に作成されたJSONStoreを取得する方法

これは、アプリケーションの後続実行時(アプリケーションが最初に実行され、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:"); 
} 

答えて

-1

.initを呼び出すと、既に作成されたコレクションは消去されません。 .destroyを呼び出すだけで、既に作成されたコレクションが破棄されます。そうすれば、次のinitで(再)作成されます。

+0

initとgetを使ってチェックする構文は何ですか? – Tim

+0

それを確認するのはもっとカスタム実装です。次のファイルで例を見ることができます。 'onlineAuthenticationSuccess()'関数を参照してください:https://github.com/MobileFirst-Platform-Developer-Center/OfflineAuthentication/blob/release71/apps/OfflineAuthSample/common/js/main.js –

+0

Idan、あなたが言いました。次のinitで(再)作成されます。 "...オブジェクトが永続化されているコレクションのポイントではなく、ただフェッチできますか?毎回それを作り直さなければならないのであれば、それは本当に永続的ではありません。おそらくそれは私の間違った前提でしたか? – Tim

関連する問題