问题
I want to create a html page which synchronize JSON data with pouch Db. The JSON data is a response from a web service.I have created a sample html file which can create a pouch Db database.I have created rest web service which gives certain data as response. can any one help me to synchronize these two.
回答1:
PouchDB has a built in method for synchronizing with CouchDB using one- or two-way replication.
I understand that you want to sync with a datasource, which doesn't have a CouchDB compatible API. Then you'll have to write code to perform the synchronization with your specific JSON API.
回答2:
There's a library now which makes it possible to import a JSON string (dump) as database into PouchDB.
It's called PouchDB-Load and is written by PouchDB author Nolan Lawson.
So in your case the code can be as simple as:
var db = new PouchDB('my-awesome-db');
db.load('http://example.com/my-dump-file.json').then(function () {
// done loading!
}).catch(function (err) {
// HTTP error or something like that
});
来源:https://stackoverflow.com/questions/21136107/synchronizing-pouchdb-with-json-data