Open mohammadchehab opened 11 years ago
Use saveChanges the promise way: saveChanges() .then(function(){ handle success here }) .fail(function(reason){ handle error here });
online.onReady(function (online) {
console.log("ready");
online.vCrews.toArray(function ( crews ) {
offline.onReady(function (offline) {
offline.vCrews.addMany(crews);
var promise = offline.saveChanges();
console.log(promise);
promise
.done(function () {
console.log("done");
})
});
});
});
Result
Promise {always: function, done: function, fail: function, isRejected: function, isResolved: function…}
index.test.html:58
Not implemented!: $data.Promise.done
Exception {name: "Not implemented!", message: "$data.Promise.done", data: undefined, _getStackTrace: function}
jaydata.js:87
Uncaught Not implemented!: $data.Promise.done jaydata.js:91
DefaultError: DEFAULT ERROR CALLBACK!
Exception {name: "DefaultError", message: "DEFAULT ERROR CALLBACK!", data: Arguments[1], _getStackTrace: function}
jaydata.js:87
Uncaught DefaultError: DEFAULT ERROR CALLBACK! jaydata.js:91
promise .then() .fail()
you also need a promise library if you already use jQuery then that is enough otherwise use q promise
Am using jQuery and this is what i have tried please tell me where am i wrong
online.onReady(function (online) {
online.vCrews.toArray(function (crews) {
offline.onReady(function (offline) {
offline.vCrews.addMany(crews);
var promise = offline.saveChanges();
console.log(promise);
promise
.then(function () {
console.log("then");
})
.fail(function () {
console.log("fail");
})
});
});
});
result
Promise {always: function, done: function, fail: function, isRejected: function, isResolved: function…} index.test.html:61 Not implemented!: $data.Promise.then
Exception {name: "Not implemented!", message: "$data.Promise.then", data: undefined, _getStackTrace: function} jaydata.js:87 Uncaught Not implemented!: $data.Promise.then jaydata.js:91 DefaultError: DEFAULT ERROR CALLBACK!
Exception {name: "DefaultError", message: "DEFAULT ERROR CALLBACK!", data: Arguments[1], _getStackTrace: function} jaydata.js:87 Uncaught DefaultError: DEFAULT ERROR CALLBACK!
The funny thing is when am quering data from a store this works like a charm however in here its not working am missing something just dont know what is it yet.
You have to include jaydatamodules/deferred.js
@agdolla you are a genius. Thank YOU !!
Actually, you should not include deferred.js or qDeferred.js manually, it should work automagically. The reason I think why it does not work for you only with manual include is that you include jquery after jaydata. Could you please include jquery before jaydata and remove the manual inclusion of deferred and try it ?
any problems with this ? it is working just fine
not at all am including jquery before jayData here is the code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Progress Everywhere</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" type="text/css" href="assets/jquerymobile/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" type="text/css" href="assets/custom.css" />
<script type="text/javascript" src="assets/jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="assets/jquerymobile/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="assets/datajs/datajs-1.0.3.js"></script>
<script type="text/javascript" src="assets/jaydata/jaydata.js"></script>
<script type="text/javascript" src="assets/jaydata/jaydatamodules/deferred.js"></script>
<script type="text/javascript" src="assets/jaydata/jaydataproviders/oDataProvider.js"></script>
<script type="text/javascript" src="core/PlannerEntities/PlannerEntities.js"></script>
<script type="text/javascript" src="core/monitor/monitor.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="assets/knockout/knockout-2.2.0.js"></script>
<script type="text/javascript" src="messages/messages.js"></script>
<script type="text/javascript">
I'm glad that it works for you but on the other hand it should work without manual include. Let us leave this issue open so we do not forget to investigate. Which version of jaydata do you use ?
the latest 1.2.6 (taken from jayData.js "// JayData 1.2.6")
Is this still being looked into? I have the same issue, however I am using the q library (not including jQuery).
I am using angular as well, which has it's own q/promise implementation, not sure if that is causing an issue?
can you post some code?
including scripts:
<!-- build:js scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script type="text/javascript" src="components/q/q.min.js"></script>
<script type="text/javascript" src="components/jaydata/jaydata.min.js"></script>
<script type="text/javascript" src="components/jaydata/jaydatamodules/deferred.min.js"></script>
<script type="text/javascript" src="scripts/factories/storage.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/header.js"></script>
<!-- endbuild -->
test code:
var promise = $sa.db.UserInfo.toArray();
promise.then(testCallback);
function testCallback(data) {
data.forEach(
function (entity) {
console.log(entity);
}
);
}
This results in:
Not implemented!: $data.Promise.then
Exception {name: "Not implemented!", message: "$data.Promise.then", data: undefined, _getStackTrace: function}
I know the database works because if I don't use promises the data is returned.
well basically i have used q library and i found that the same thing you can do with jQuery's deferred objects. what you can do is the following:
var done = function(){ console.log("yay"); }; var error = function(e){ console.log("woops " + e.message); } online.Friends.toArray().then(function(its){ local.Friends.addMany(its); var promise = db.saveChanges(); promise.fail(error); promise.done(done); });
if that doesn't help and you still want to work with Q i belive that jayData has support for q.js instead of adding deferred.js add this file jaydatamodules/qDeferred.js
Including qDeferred worked. Thank you! Took me nearly 3 hours to figure that out.
Cheerz!!
While Saving the first time i get a success with no problems. However when i try to save again primary keys exceptions are cought in the console however i cannot catch them using try catch blocks to raise an error. `javascript offline = new PlannerServiceLibrary.PlannerEntities({ name: 'sqLite', databaseName: 'progressdb' });