2013-10-12 28 views
2

我有,我想用过滤商店的路线,但它的使用属性,是不是对模型本身在ember.js中路由非模型参数的习惯用法是什么?

App.Appointment = DS.Model.extend({              
    details: attr('string')           
}); 

App.Router.map(function(match) {            
    this.resource("appointments", { path: "/appointments" }, function() {  
     this.route("index", { path: "/:day/all" });     
    });                   
}); 

当我打的模型法这条路,我简单查询api使用这个“日”属性(因为它是查询后端的合法方式)。但是因为它不是模型的一部分,我不认为这是“应该”应用的方式。

App.AppointmentsIndexRoute = Ember.Route.extend({ 
    model: function(params) { 
     return this.store.find('appointment', params); 
    } 
}); 

我应该如何编写一个没有公开模型属性的ember模型的路由?

我还应该提到,当setupController方法被调用时,因为注入的“model”参数是{day:“2013-01-01”}而不是约会模型数组(I可以破解解决这个,但感觉就像我做错了)

回答

0

我发现创建一个哈希对象解决了这个问题(所以直到查询参数都支持这个,感觉少哈克的一个很好的解决方案)

App.AppointmentsIndexRoute = Ember.Route.extend({ 
    model: function(params) { 
    return Ember.RSVP.hash({ 
     appointments: this.store.find('appointment', params), 
     day: params.day 
    }); 
    }, 
    setupController: function(controller, model) { 
    controller.set('model', model.get('appointments')); 
    controller.set('day', model.get('day')); 
    } 
}); 

我还应该证明,如果你创建一个linkTo helper或者转换到这条路线,你需要这样做

App.IndexRoute = Ember.Route.extend({           
    redirect: function() {              
     var now = new Date();             
     var today = moment(now).format('YYYY-MM-DD');       
     this.transitionTo('appointments.index', today);       
    }                   
}); 
相关问题