私はAddress ---> Countryの関係を持っているとしましょう。アドレスフォームには国のコンボボックスがあります。国を選択すると、選択した国のメソッドが呼び出されます。IDを渡してコンボボックスを選択したときにメソッドを呼び出す方法は?
<select #countryCB class="form-control" id="field_country" name="country" [(ngModel)]="sponsorAgreement.country" required (change)="onChangeCountry(countryCB.value)">
<option [ngValue]="countryOption.id === address.country?.id ? address.country : countryOption"
このコードの問題点は、国のIDではなくインデックス(リストの第1国、第2国...)を渡すことです。
私はコードをデバッグしようとしましたが、そのIDはコンボ自体にはなく、私には得られないメカニズムがtrackByCountryID
であることに気付きました。あなたが見ることができるように、これは、生成されたもの何らIDではありません:
<option [ngValue]="countryOption.id === address.country?.id ? address.country : countryOption"
それは(インデックス付き)次のHTMLコードを生成します:
<option value="2: Object"
これとそう
<select class="form-control ng-untouched ng-pristine ng-valid" id="field_country" name="country" ng-reflect-name="country" ng-reflect-model="[object Object]">
<option value="0: null"></option>
<option value="1: Object" ng-reflect-ng-value="[object Object]">Andorra</option>
<option value="2: Object" ng-reflect-ng-value="[object Object]">United Arab Emirates</option>
<option value="3: Object" ng-reflect-ng-value="[object Object]">Afghanistan</option>
これに変更した場合:
<option [ngValue]="countryOption.id === address.country?.id ? address.country.id : countryOption.id"
これは、(ID付き)以下のHTMLを生成します
<option value="1001: 1001"
しかし、その後、背面のRESTサービスの中断は誰もがIDを取得する方法を知ってい
Bad Request: JSON parse error: Can not construct instance of io.quantixx.sponsor.domain.Country: no int/Int-argument constructor/factory method to deserialize from Number value (4); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of io.quantixx.sponsor.domain.Country: no int/Int-argument constructor/factory method to deserialize from Number value (4)
at [Source: [email protected]; line: 8, column: 14] (through reference chain: io.quantixx.sponsor.domain.Address["country"])
2017-11-18 07:55:44.081 WARN 43780 --- [ XNIO-2 task-14] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not construct instance of io.quantixx.sponsor.domain.Country: no int/Int-argument constructor/factory method to deserialize from Number value (4); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of io.quantixx.sponsor.domain.Country: no int/Int-argument constructor/factory method to deserialize from Number value (4)
at [Source: [email protected]; line: 8, column: 14] (through reference chain: io.quantixx.sponsor.domain.Address["country"])
を更新/作成? trackByCountryID
は関与していますか?
おかげ