You only need to call init if you are opening a collection for the first time, or reopening it after closing the store. You only want to close the store if you are done using JSONStore and want to close it for security purposes, or if you want to switch to another JSONStore user if you are using multiple users. If you have no need for these two situations, you do not have to close the store.
You can definitely init the collection(s) at startup and have them open for the rest of the app's lifecycle, and then close it when the app closes, for example. You do not have to call init when you call get, or any other JSONStore method; you only have to call init, as i said, when you are using the collection for the first time, or after you closed or destroyed the store (by calling WL.JSONStore.closeAll() or WL.JSONStore.destroy()).
As for the error you are getting, it most likely means that you are passing different fields the second time you call init, and you cannot do that, since search fields cannot be changed dynamically. If you want to change the search fields, you first have to remove that collection (and lose the data inside it), and then reinitialize it with the new data.
To verify that you can call init multiple times (with the same arguments), you can run the following sample code:
var collections = {
people : {
searchFields : {name: 'string'}
},
orders : {
searchFields: {name: 'string'}
}
};
WL.JSONStore.init(collections)
.then(function () {
return WL.JSONStore.init(collections);
})
.then(function () {
return WL.JSONStore.init(collections);
})
.then(function () {
//init called 3 times succesfully
alert('Multiple inits worked');
})
.fail(function (err) {
//this should not be called
alert('Multiple inits failed' + err.toString());
});