AngularJS中update兩次出現(xiàn)$promise屬性無法識(shí)別的解決方法
前言
本文主要介紹的是在AngularJS中update兩次出現(xiàn)$promise屬性無法識(shí)別的解決方法,下面話不多說,先來看看錯(cuò)誤提示,然后再看看解決的辦法吧。
一、錯(cuò)誤信息如下:
ERROR 2015-12-02 14:33:17,653 http-bio-8080-exec-42 o.s.s.r.i.e.InternalErrorExceptionMapper - Unrecognized field "$promise" (class com.inetpsa.fnd.rest.client.ClientRepresentation), not marked as ignorable (6 known properties: "lastName", "address", "telephone", "clientId", "mail", "firstName"]) at [Source: org.apache.catalina.connector.CoyoteInputStream@1b9d797d; line: 1, column: 357] (through reference chain: com.inetpsa.fnd.rest.client.ClientRepresentation["$promise"]) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "$promise" (class com.inetpsa.fnd.rest.client.ClientRepresentation), not marked as ignorable (6 known properties: "lastName", "address", "telephone", "clientId", "mail", "firstName"]) at [Source: org.apache.catalina.connector.CoyoteInputStream@1b9d797d; line: 1, column: 357] (through reference chain: com.inetpsa.fnd.rest.client.ClientRepresentation["$promise"]) at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51) ~[jackson-databind-2.4.4.jar:2.4.4] at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:744) ~[jackson-databind-2.4.4.jar:2.4.4] at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:915) ~[jackson-databind-2.4.4.jar:2.4.4] at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1306) ~[jackson-databind-2.4.4.jar:2.4.4] at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1284) ~[jackson-databind-2.4.4.jar:2.4.4] at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:243) ~[jackson-databind-2.4.4.jar:2.4.4] at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118) ~[jackson-databind-2.4.4.jar:2.4.4]
二、問題代碼

Angular 自動(dòng)會(huì)在返回的data數(shù)據(jù)中帶上$promise屬性。

在進(jìn)行下面copy時(shí)將從data返回的數(shù)據(jù)copy到當(dāng)前行用來顯示,這樣在進(jìn)行update的操作時(shí)帶的數(shù)據(jù)體中就包含了$promise屬性,結(jié)果就會(huì)出現(xiàn)上述錯(cuò)誤導(dǎo)致update失敗。

三、更改如下:
// ===============show the update modal dialog ==================
$scope.tempRowEntityForUpdate;
$scope.openUpdateClientPopup=function(){
$scope.form1.$setSubmitted(true);
$scope.tempRowEntityForUpdate = {};
angular.copy($scope.currentSelectedRowEntity, $scope.tempRowEntityForUpdate);
angular.element('#UpdateDialog').modal({
backdrop: false
});
};
$scope.updateClient=function(){
if($scope.form1.$submitted && $scope.form1.$valid){
Client.update({},$scope.tempRowEntityForUpdate,function(){
angular.copy($scope.tempRowEntityForUpdate,$scope.currentSelectedRowEntity);
});
angular.element('#UpdateDialog').modal('hide');
}
};
解決辦法:不使用更新后獲得的data數(shù)據(jù),而是從當(dāng)前的行模型中取得數(shù)據(jù)copy給當(dāng)前選中的行即可。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
相關(guān)文章
AngularJS入門教程之AngularJS表達(dá)式
AngularJS應(yīng)用表達(dá)式是純javascript表達(dá)式,并輸出它們被使用的數(shù)據(jù)在那里。本文給大家介紹AngularJS入門教程之AngularJS表達(dá)式,對(duì)angularjs表達(dá)式相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-04-04
Angular2使用Augury來調(diào)試Angular2程序
這篇文章主要介紹了Angular2使用Augury來調(diào)試Angular2程序,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-05-05
angular 基于ng-messages的表單驗(yàn)證實(shí)例
本篇文章主要介紹了angular 基于ng-messages的表單驗(yàn)證實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05
angular報(bào)錯(cuò)can't resolve all parameters&nb
這篇文章主要介紹了angular報(bào)錯(cuò)can't resolve all parameters for []的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
AngularJs 動(dòng)態(tài)加載模塊和依賴
這篇文章主要介紹了AngularJs 動(dòng)態(tài)加載模塊和依賴方法的相關(guān)資料,需要的朋友可以參考下2016-09-09

