我正在嘗試這樣做:我有一個名爲'trip'的模型,並且在旅程中,名爲'createdToday'的屬性返回創建旅行的日期。我想要的是返回今天所做的旅行列表。Ember今天創建的模型的返回長度
這是我此行模式:
import DS from 'ember-data';
export default DS.Model.extend({
driver: DS.belongsTo('driver', {
async: true,
inverse: 'trip'
}),
..... etc .......
createdAt: DS.attr('string', {
defaultValue() {
return new Date();
}
}),
isBookedToday: function(trip) {
var today = new Date().toDateString();
return (today === trip.get('createdAt').toDateString);
},
getTripsToday: Ember.computed('[email protected]', function() {
var tripsToday = this.get('trip');
return tripsToday.filterBy('isBookedToday', true).get('length');
})
});
在我isBookedToday,我想看看如果一個個體出行的創建時間是一樣的今天的時間,並在getTripsToday,我通過努力環所有旅行和過濾isBookedToday。
而在我的.hbs文件中,我說:{{trips.getTripsToday}},它不會呈現任何內容,所以出現了錯誤。
我想我最困惑於Ember的@each以及它究竟是如何工作的。
感謝您的任何反饋意見。