Reputation: 546
I'm working on a controller that reloads data when data is received from a websocket. I've got it working up to the point of reloading the data. I'm not sure why this isn't working, but I'm getting an error when I call self.get('contact').reload(); below. 'object has no method reload'. I'm pretty sure I'm calling this incorrectly, but I'm not sure how to reload the data from the store. Could someone help me out?
CallMonitor.ContactsRoute = Ember.Route.extend({
model: function(){
return this.store.find('contact');
},
setupController: function(controller, contacts) {
var socket = io.connect('http://localhost:3000');
controller.set('socket', socket);
controller.set('contact', contacts);
}
});
CallMonitor.ContactsController = Ember.ArrayController.extend({
socketDidChange: function(){
var socket = this.get('socket'),
self = this;
if(socket)
{
socket.on('call', function (data) {
var contactToUpdate = self.contact.filter(function(item) {
return item.id == data.contactId;
});
if(contactToUpdate.length)
{
contactToUpdate.reload();
}
else
{
// reload all the contacts
self.get('contact').reload();
}
});
}
}.observes('socket')
});
Upvotes: 2
Views: 243
Reputation: 546
I ended up just doing another fetch from the store and then setting the controller's contact property again. Couldn't find an easy way to do a reload for multiple records. For single records, it's easy to just do a "reload()" but for new records and such it's apparently not that easy.
var contactPromise = self.contact.store.find('contact');
contactPromise.then(function(data){
self.set('contact', data);
}, undefined);
Kind of a bummer. Also couldn't find a good way to remove records in ember data.
Upvotes: 1