2013-02-26 49 views
2

我正在编写一个应用程序,它通过Node.js利用Ember.js,Ember Data和Socket.IO。我试图找出从插座响应接收数据,并将其加载到我的灰烬数据存储,如最好的方法:如何从Socket.IO响应中将数据加载到Ember数据中?

window.socket = io.connect('http://localhost'); 

socket.on('action here', function(response) { 
    // how to load "response" JSON data into Ember Data store from here...? 
}); 

是写一个自定义的最好的(或唯一的好)解决方案DS.Adapter?或者还有另一种很好的,可维护的方法来完成这个?

回答

1

为了记录在案,我结束了在这里提出的答案会:

https://stackoverflow.com/a/14508316/1470194

使用Ember.Instrumentation技术,我能方便到我的控制器调用和访问我的商店的方式。

我意识到在许多情况下编写自定义适配器可能是必要的,但它超出了我的项目的要求范围,所以此解决方案最终变得完美。

4

最好的办法是写自己的适配器,但是如果你只需要加载模型(无豁免),您可以用适配器的load方法脱身 - 是这样的:

socket.on('single-model', function(response) { 
    DS.defaultStore.load(response); 
}); 

socket.on('multiple-models', function(response) { 
    for(i in response){ 
     DS.defaultStore.load(response[i]); 
    } 
}); 

定义适配器为FixtureAdaptor

相关问题