我在detailpage
中用API
写了以下代码来进行评级和审查。一旦我提交评论和评论。数据没有同时显示。如果我移至上一页并再次进入detailpage
,则显示数据。在Myreview
和All review
部分中。在同一时间单击同一页面后如何显示数据?请帮忙。
下面是ts文件
reviewComment(elm){
this.commentValue = elm.comment;
console.log(this.commentValue);
this.authService.securePostData("listing_id="+this.listing.id+"&rating="+this.starValue+"&comment="+this.commentValue,"review/add",).then((result) => {
this.reviewResult = result;
let toast = this.toastCtrl.create({
message: 'Review added successfully',
duration: 4500,
position: 'bottom'
});
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
toast.present();
console.log(result);
})
}
myReview(){
if (JSON.parse(localStorage.getItem('userStorage')) != null) {
this.authService.securePostData("listing_id="+this.listing.id,"myreview",).then((result) => {
this.myreviews = result;
this.myreview = this.myreviews.review;
console.log(this.myreview);
})
}
}
allReview(){
this.authService.postData("listing_id="+this.listing.id,"reviews",).then((result) => {
var resData = result['data'];
this.allreview = [];
resData.forEach(element => {
var dd = new Date(element.created_at);
element.ogdate = ("0" + dd.getDate()).slice(-2)+"-"+("0" + (dd.getMonth() + 1)).slice(-2)+"-"+dd.getFullYear();
this.allreview.push(element);
});
})
}
这是html
<ion-row *ngIf="!myreview?.id">
<ion-col class="addrev">
<div style="font-size: 22px;">Add Review</div>
<rating (click)="reviewStar(this)" [(ngModel)]="rate"
readOnly="false"
max="5"
emptyStarIconName="star-outline"
halfStarIconName="star-half"
starIconName="star"
nullable="false"
>
</rating>
<ion-textarea [(ngModel)]="comment"></ion-textarea>
<button ion-button (click)="reviewComment(this)">Submit Review</button>
</ion-col>
</ion-row>
<ion-row class="myreviws" *ngIf="myreview?.id > 0">
<h4>My Review</h4>
<ion-item>
<ion-grid>
<ion-row>
<ion-col col-3>
<img src="{{myreview?.user.profile_image}}">
</ion-col>
<ion-col col-9>
<span class="name">{{myreview?.user.name}}</span>
<p class="rating">
<ion-icon ios="ios-star" md="md-star" *ngIf="myreview?.rating > 0"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="myreview?.rating > 1"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="myreview?.rating > 2"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="myreview?.rating > 3"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="myreview?.rating > 4"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="myreview?.rating < 1"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="myreview?.rating < 2"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="myreview?.rating < 3"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="myreview?.rating < 4"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="myreview?.rating < 5"></ion-icon>
{{myreview?.ogdate}}
</p>
<p class="comment">{{myreview?.comment}}</p>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</ion-row>
<h4>All Reivew</h4>
<ion-row class="allreviws" *ngFor="let allreviews of allreview">
<ion-item>
<ion-grid>
<ion-row>
<ion-col col-3>
<img src="{{allreviews.user.profile_image}}">
</ion-col>
<ion-col col-9>
<span class="name">{{allreviews.user.name}}</span>
<p class="rating">
<ion-icon ios="ios-star" md="md-star" *ngIf="allreviews.rating > 0"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="allreviews.rating > 1"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="allreviews.rating > 2"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="allreviews.rating > 3"></ion-icon>
<ion-icon ios="ios-star" md="md-star" *ngIf="allreviews.rating > 4"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="allreviews.rating < 1"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="allreviews.rating < 2"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="allreviews.rating < 3"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="allreviews.rating < 4"></ion-icon>
<ion-icon ios="ios-star-outline" md="md-star-outline" *ngIf="allreviews.rating < 5"></ion-icon>
{{allreviews.ogdate}}
</p>
<p class="comment">{{allreviews.comment}}</p>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</ion-row>