我在後臺使用了Onymos。當我從onymos提取數據時,它給了我一個「排列方式」屬性,我可以指定「createdTime」作爲值,但是,由於某些原因,這並不適用於我的模板。我不認爲有一個命令的命令在我的谷歌搜索的角度了。所以我不知道我還可以在我的模板中訂購。 我的服務將數組傳遞給在主TS頁面的contstructor中觸發的回調函數。 我爲此付出了代價,因爲某人提供的第一個解決方案並不適合我......一直導致錯誤。如何根據最近創建的內容列出Feed中的帖子?
home.html做爲
<ion-card id="card" *ngFor="let event of listOfEvents" >
<ion-row id="row1">
<ion-col>
<span class="showDetails">Date:</span>
{{getFormattedTime(event.eventTime, 'MM-dd-yyyy')}}
</ion-col>
<ion-col>
<span class="showDetails">Time:</span>
{{getFormattedTime(event.eventTime, 'HH:MM')}}
</ion-col>
<ion-col>
<span class="showDetails">Venue:</span>
{{event.venue}}
</ion-col>
</ion-row>
</ion-card>
MyService.TS
getPosts (selectedCity, successCallback, failureCallback) {
OnymosUtil.getData(
'/events/' + selectedCity,
function getPostsSuccess (listOfEventsObject){
successCallback(listOfEventsObject);
},//close function getPostSuccess
function getPostsFailure (error) {
failureCallback(error);
},
{
orderByField: 'createdTime', //OrderByField not working
limitToFirst: 100
});
}//end getPosts
HOME.TS
export class Home {
listOfEvents: Array<any> = [];
postEvent: any;
constructor (public navCtrl: NavController,
public popoverCtrl: PopoverController,
public getPostSrvc: getPostsService) {
this.listOfEvents = [];
let that = this;
this.getPostSrvc.getPosts(
this.selectedCity,
function getPostsSuccess (listOfEventsObject) {
for (var i in listOfEventsObject) {
that.listOfEvents.push(listOfEventsObject[i]);
}
},
function getPostsFailure (error) {
console.log('ERROR : home.ts : Failed retrieving Posts - ' + error);
});
}//close constructor
}//close class
這樣的排序函數內部將我的每個項目重新推到一個數組?我需要一個數組傳遞給模板。我不確定a,b,參數如何幫助.. – Spilot
查看JavaScript排序文檔。 – theblindprophet
我開始賞金,因爲我仍然在尋找更多的答案... – Spilot