Ember Websocket ...找不到任何记录? [英] Ember Websocket...can't find any records?

查看:180
本文介绍了Ember Websocket ...找不到任何记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我被阻止无法从我的livestream websocket中引入数组,这是以JSON的形式进行的。

So, I'm stuck not being able to bring in arrays from my livestream websocket, which is coming through as JSON.

没有在ember检查器中看到任何记录,但是很多用console.log(数据)打印出来。获取错误:

Not seeing any records in ember inspector, but plenty is printing out with console.log(data). Getting error:

-94 Uncaught Error: Assertion Failed: You must include an `id` in a hash passed to `push` 

(但每个livestream更新中都包含一个ID)。

(but there is an ID included in each livestream update).

以下是代码: http:// jsbin .com / qapik / 1 / edit?html,js,output

Here's the code: http://jsbin.com/qapik/1/edit?html,js,output

JSON看起来像...

JSON looks like...

{
    "group":{
        "usage":{
            "case1":0,
            "case2":0,
            "case3":0
        },
        "sunshine":"00/00/0000",
        "id":1010,
        "device_info":11.5,
    }
}

更新...

Tue Apr 01 2014 09:22:09 GMT-0400 (EDT): group update: {"group": ...

在一天结束时,我想显示{{#each} } {{device_info}} ...等等。

At the end of the day, I want to show {{#each}} {{device_info}}... and more.

我在哪里出错?

谢谢!

编辑 - 解决方案:

App.ApplicationRoute = Ember.Route.extend({
    activate: function() {                
        var socket = window.io.connect('http://localhost:8887');                                                           
        var self = this;                                                                                                   

        socket.on('group_live_stream', function(data){                                                                               
            var dataObj = JSON.parse(data); // data happens to be a JSON string
            self.store.push('group',dataObj.group);                                                                              
        });                                                                                                                
     }
});


推荐答案

推送到商店的物品应格式如示例如下: http://emberjs.com/api/data/classes/ DS.Store.html#method_push

Objects pushed onto the store should be formatted like in the example here: http://emberjs.com/api/data/classes/DS.Store.html#method_push

{
    "usage":{
        "case1":0,
        "case2":0,
        "case3":0

    },
    "sunshine":"00/00/0000",
    "id":1010,
    "device_info":11.5
}



换句话说,当你把它推到商店时,对象不应该被包裹在 group 中。这与Ember Data预期使用REST适配器的JSON响应有何区别(当ED获得组记录时,确实会期望像 {group:{...}} )。

In other words, when you're pushing it onto the store, the object should not be wrapped in group. This is notably different than how Ember Data expects JSON responses using it's REST adapter (when ED gets a group record, it does indeed expect an object like {group:{...}}).

这篇关于Ember Websocket ...找不到任何记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆