完成api调用后。在我的数据库中,我有一组json对象值。结构如下:如何调用对象值ionic 2
{
"status": 1,
"message": "List Successfully fetched",
"CatgeoryList": [
{
"CatID": "10"
},
{
"CatID": "30"
},
{
"CatID": "0"
}]
}
我已经完成了api调用。我得到了status == 1
。我可以打印CatgeoryList
中的所有对象值。但我想打印所有catID
中的IN CatgeoryList
。我无法得到。
这里我的代码:
this.authService.categ(this.loginData).then((result) => {
this.loading.dismiss();
this.data = result;
if(this.data.status == 1)
{
this.Catdata = this.data.CatgeoryList;
console.log(this.Catdata); // i am getting all data
this.Catdatanames = this.Catdata.CatID; // not working
console.log(this.Catdata.CatID); // not working
}
}
我想要得到的catID
下CatgeoryList
。
更新:更新的
home.html的:
<div class="item item-body no-padding" style="border-width: 0px !important;">
<div class="row no-padding" *ngFor="let data of Catdata;let i = index" (click)="opndetailpage()">
<ng-container *ngIf=" i % 2 === 0">
<div class="col col-50 custom-design2" style="background: url(url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{Catdata[i].CategoryName}}</span></div>
</div>
<div class="col col-50 custom-design2" style="background: url(url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{Catdata[i+1].CategoryName}}</span></div>
</div>
</ng-container>
</div>
</div>
home.ts
constructor(
public alertCtrl: AlertController,
public app: App,
public loadingCtrl: LoadingController,
public modalCtrl: ModalController,
public navCtrl: NavController,
public toastCtrl: ToastController,
public confData: ConferenceData,
public user: UserData,
public http:Http,
public authService: AuthService
) {
this.showLoader();
this.authService.categ(this.loginData).then((result) => {
this.loading.dismiss();
this.data = result;
if(this.data.status == 1)
{
this.Catdata = this.data.CatgeoryList;
for(let i=0; i<this.Catdata.length; i++) {
console.log(this.Catdata[i].CategoryName);
}
}
else if(this.data.status == 0) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: 'Please Enter Valid Username & Password',
buttons: ['OK']
});
alert.present();
}
}, (err) => {
this.loading.dismiss();
});
}
我takeexam.html
<ion-buttons>
<button (click)="canceltap()" style="font-size: 15px;text-transform: none;" ion-button>Cancel
</button>
</ion-buttons>
我takeexam.ts
canceltap() {
// this.navCtrl.pop();
console.log("pop tap");
this.navCtrl.setRoot(TabsPage); .// this is my home page
}
所以当我按下取消按钮takeexam.html
其将A型行为[age.html(主页)。但是没有数据显示。我只是用硬编码在我的主页上尝试了一些价值。那次我按取消按钮显示所有数据。
所以我发现问题是在ionviewdidload或其他一些数据。我试过了。 ionViewDidEnter
ionDidLoad
。但没有任何工程
我没有看到json中的'CategoryName'全部为 –
也'CatData'是一个数组。如何将'this.Catdatanames = this.Catdata.CategoryName; //不工作'没有循环工作? –
@suraj对不起,我的错误。我已经更新 – venky