這些天來,我已經學會breezejs,durandaljs,所以我做了一個excersizing溫泉申請,但breezejs(或q.js)經常給出錯誤Breezejs [Q]未處理的拒絕原因(應爲空)
[Q] Unhandled rejection reasons (should be empty): ["[email protected]:...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 ?)
我對使用breezejs感到失望,我到底在做什麼!
我只是做保存和刪除客戶,有時上面發生錯誤時,有時工作正常(我是多麼糊塗的感覺。!「( )
這裏是我的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; } };
要保存客戶:
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;
});
刪除一個客戶
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(); } });
我覺得我的代碼將正常工作,但它不能!
我犯的致命錯誤在哪裏?請讓我知道。
提前致謝!
可能重複[未處理的拒絕原因(應該是空的)](http://stackoverflow.com/questions/ 17544965/unhandled-rejection-reasons-should-empty) –
你給的答案不適用於我。 – Kratos
@PWKad你解決了這個問題...我有同樣的問題? –