我已經具有相關下拉菜單和一些輸入fields.I表單創建想在2種情況如何操作離子2中.ts文件的下拉值?
- 工作最初如果會話爲null,則應該有形式沒有數據,所有的字段應該(我已創建)
- 如果有會話,然後我從Web API拉取JSON格式的數據,然後我想填充相應的字段。
<ion-item>
<ion-label>State</ion-label>
<ion-select (ionChange)="setCountyValues(sState)" [(ngModel)]="sState" >
<ion-option [value]="sState" *ngFor="let sState of states" [selected]="sState">{{sState.name}}</ion-option>
</ion-select>
</ion-item>
<ion-item *ngIf="selectedCounties">
<ion-label>Counties</ion-label>
<ion-select (ionChange)="setCityValues(sCounty)" [(ngModel)]="sCounty">
<ion-option [value]="sCounty" *ngFor="let sCounty of selectedCounties">{{sCounty.name}}</ion-option>
</ion-select>
</ion-item>
<ion-item *ngIf="selectedCities">
<ion-label>Cities</ion-label>
<ion-select [(ngModel)]="sCity">
<ion-option [value]="sCity" *ngFor="let sCity of selectedCities">{{sCity.name}}</ion-option>
</ion-select>
</ion-item>
<ion-item *ngIf="selectedCities">
<button ion-button round color="primary" (click)="clear()">Clear</button>
<button ion-button round color="primary" (click)="goToOfficeDetail()">Office Detail Page</button>
</ion-item>
<ion-item>
<button ion-button round color="primary" (click)="Autofill()">Autofill</button> </ion-item>
[{
"PageRec":"AL005",
"State":"AL",
"County":"Autauga County",
"CityTown":null,
"Zip":null,
"ShowRecordingInfo":"true",
"Deed":{
"Checked":"True",
"Pages":"1",
"ConsiderationAmount":"150000"
},
"MortgageDeed":{
"Checked":"False",
"Pages":null,
"NewDebtAmount":null
},
"MortgageRefi":{
"Checked":"False",
"Pages":null,
"NewDebtAmount":null,
"OriginalDebt":null,
"UnpaidDebt":null
},
"Assignment":{
"Checked":"False",
"Pages":null,
"Assignments":null
},
"ReleaseSatisfaction":{
"Checked":"False",
"Pages":null,
"ReleasesSatisfactions":null
},
"Questions":{
"Question":{
"Number":"Q4",
"Category":"Deed",
"Type":"bool",
"Question Text":"Are the deed and ``mortgage being recorded at the same time?",
"Answer":"1"
}
}
}]
.TS
GetDocumentDetailsData()
{
this.zipcode.getDocDetails().then(data=>this.documentDetails=data);
}
Autofill()
{
this.GetDocumentDetailsData();
this.sState = this.documentDetails.State;
}
我的問題是,當我試圖填補下拉那麼爲什麼顯示的問題說找不到財產「國家「的未定義
非常感謝@ AJT_82 ..現在工作正常,萬一我有會議中的東西...但如果它是一個新用戶,那麼它應該是空白的。但是現在我有[選擇] =「sState」,當sState中沒有單一狀態時,它會選擇所有的東西...我應該單獨編寫它的ngIf還是還有其他更好的解決方案? –
什麼意思與***但現在我有[選擇] =「sState」,它會選擇一切,當沒有單一狀態在sState ***它選擇什麼,它不應該選擇任何東西,如果sState'有沒有預設值? – Alex
是的......所以當sState中沒有數據時,它會選擇所有的東西......就像4個刻度一次來到,如果我在狀態中有4個條目 –