So I've set up a router and some routes, and this works for the most part. when I load #/contacts/123 (or whatever) the ContactIndexRoute returns an empty params object. I'm sure this is relatively simple, but I cannot figure out why. Can someone point me in the right direction? Thanks.
CallMonitor.Router.map(function(){
this.resource('contacts', function(){
this.resource('contact', {path: '/:contact_id'}, function(){
})
});
});
CallMonitor.ContactsRoute = Ember.Route.extend({
model: function(){
return this.store.find('contact');
},
setupController: function(controller, contacts) {
var socket = CallMonitor.Socket;
controller.set('socket', socket);
controller.set('contact', contacts);
},
renderTemplate: function(){
this._super(this, arguments);
this.render('contacts', {
into: 'application',
outlet: 'contacts',
controller: 'contacts'
});
}
});
CallMonitor.ContactIndexRoute = Ember.Route.extend({
model: function(params){
return this.store.find('contact', params.contact_id);
},
renderTemplate: function(){
this._super(this, arguments);
this.render('contact', {
outlet: 'points',
into: 'contacts',
controller: 'contactsIndex'
})
},
setupController: function(controller, contact) {
controller.set('contact', contact);
}
});
CallMonitor.ContactsController = Ember.ArrayController.extend({
actions: {
getPoints: function(data){
this.transitionToRoute('contact', data.id);
console.log('the data is' + data );
}
},
socketDidChange: function(){
var socket = this.get('socket'),
self = this;
if(socket)
{
socket.on('call', function (data) {
if(data.contactPointId){
}
else if (data.contactId)
{
var contactToUpdate = self.contact.filter(function(item) {
return item.id == data.contactId;
});
if(contactToUpdate.length)
{
contactToUpdate[0].reload();
}
else
{
// reload all the contacts
var contactPromise = self.contact.store.find('contact');
contactPromise.then(function(data){
self.set('contact', data);
}, undefined);
}
}
});
}
}.observes('socket')
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…