These days,i have learned breezejs,durandaljs, so i made an spa application for excersizing,but breezejs(or q.js) often gives out errors
[Q] Unhandled rejection reasons (should be empty): ["proto.saveChanges@http:...s/jquery-1.9.1.js:2750\n"] (Firefox)
[Q] Unhandled rejection reasons (should be empty):(no stack) Error: Client side validation errors encountered - see the entityErrors collection on this object for more detail (IE10, but why deleteing an entity triggers validation ?)
I feel disappointed to use breezejs, what on earth am i doing!!!
I just do saving and deleting customer, sometimes error occured as above, sometimes works fine.(how confused i am feeling! :'( )
Here is part of my datacontext
var saveChanges = function () { return manager.saveChanges() .then(saveSuccess) .fail(saveFailure); //.done() does not work either // function saveSuccess() { console.log("Save Success!"); } // function saveFailure(error) { console.log("Save Failure!"); throw error; } };
To save a customer:
define(['modules/dataService'], function (datacontext) {
var ctor = function () {
this.entity = ko.observable();
};
ctor.prototype.activate = function () {
//problem code --> [Q] Unhandled rejection reasons (should be empty)
//it will always create empty Customer when activate is called.
//so error occured when i switch in because of creating empty Customer every time.
this.entity(datacontext.createEntity('Customer'));
};
ctor.prototype.saveClick = function () {
if (this.entity().entityAspect.validateEntity())
datacontext.saveChanges();
else
console.log('validation error!');
};
return ctor;
});
To delete a customer
define(function (require) { var datacontext = require('modules/dataService'); var vm = { customers: ko.observableArray(), activate: function () { var self = this; return datacontext.getCustomers(self.customers); }, deleteCustomer: deleteCustomer }; return vm; //delete customer function deleteCustomer(customer) { vm.customers.remove(customer); //Sets the entity to an EntityState of 'Deleted' customer.entityAspect.setDeleted(); datacontext.saveChanges(); } });
I think my code would work fine, but it can't!
Where is the fatal error i make? plz let me know.
Thanks in advance!