2014-01-09 36 views
1

這些天來,我已經學會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(); } });

我覺得我的代碼將正常工作,但它不能!

我犯的致命錯誤在哪裏?請讓我知道。

提前致謝!

+0

可能重複[未處理的拒絕原因(應該是空的)](http://stackoverflow.com/questions/ 17544965/unhandled-rejection-reasons-should-empty) –

+1

你給的答案不適用於我。 – Kratos

+0

@PWKad你解決了這個問題...我有同樣的問題? –

回答

1

我知道這個主題已經在這裏已經超過一年了,但我想我可以分享我的故事。

我剛剛在使用breeze + angularJS時遇到了同樣的錯誤。經過一番調查,我發現:

我在一些實體的屬性中傳遞空值,而在數據庫表中標記爲NOT NULL的那些字段。

微風 - 的SaveChanges

在breeze.saveChanges實施,檢查在內部完成的標誌(線12743約:如果(this.validationOptions.validateOnSave)...)

這是爲了根據數據庫模式(也就是元數據)驗證實體。

現在大部分時間我們都傾向於在沒有任何參數的情況下調用saveChanges。並且錯誤不會在控制檯中以其他方式顯示,因爲它是一般驗證錯誤消息。

我做了什麼

我們將我的修補程序是兩個部分:

  1. 我到的SaveChanges調用爲了添加一些代碼來捕獲這些錯誤,並顯示在一個更好的消息控制檯(請參閱下面的代碼)
  2. 修復數據庫模式(即將NOT NULL字段放寬到NULLABLE)或設置一些默認值或通過向輸入控件添加必需的屬性來強制執行業務邏輯。

這裏的代碼片段我現在用捕獲的錯誤:

return manager.saveChanges(null, null, null, function (errors) { 
    console.log('breeze saveChanges returned some errors: '); 

    errors.entityErrors.forEach(function(e) { 
     console.log(e.errorMessage, e); 
    }); 
}); // return promise 
相關問題