【发布时间】:2017-06-27 21:54:51
【问题描述】:
我通过 websocket 连接以这种格式接收消息:
[
{
//msg 1
},
{
//msg 2
},
....
]
根据我在网上找到的一些示例,这是我的代码:
public messages: Subject<Message> = new Subject<Message>();
//...
this.messages = <Subject<Message>>this.wsService
.connect(COMMUNICATION_URL)
.map((response: MessageEvent): Message => {
let data = JSON.parse(response.data);
//data is an array [ {..} , {..}, ...]
return data;
});
this.messages.subscribe(msg => {
console.log(msg);
// msg is an array of objects [ {..} , {..}, ...]
// I want to be just the object
});
我想要实现的是将消息(数组)拆分为对象,当我订阅时,我想接收这些对象而不是对象数组。
【问题讨论】:
标签: javascript typescript websocket rxjs rxjs5