【发布时间】:2020-01-24 02:10:07
【问题描述】:
我正在使用具有不同事件channelName1和channelName2的api
//...this the realtime record
socket.on(channelName1, message => {
console.log(channelName1, message1);
//this return single item list in realtime`[{"price":100,"size":0.001}]`
});
//realtime snapshot collection of records
socket.on(channelName2, message => {
console.log(channelName2, message2);
//this return the collection `[{"price":100,"size":0.01}, {"price":200,"size":0.02} ]`
$('#live').text(message2)
});
如果我发现price":100 存在于集合message2 中,我想更新message2 的大小,因此更新后的message2 将
[{"price":100,"size":0.001}, {"price":200,"size":0.002} ]
谁能指导我如何从 channelName1 更新到 ChannelName2 数据?
【问题讨论】:
-
您的问题有点不清楚,如果您需要一个函数/回调变量/导致另一个函数,请创建一个两者都可以访问的变量。即创建一个名为 realtime 的变量,然后使用循环检查 channelName2 -> item.price == realtime.price -> push(item) etc
-
你能帮忙提供一些示例代码吗
-
我想通过 message1 中的 'size' 更新 message1 中的 'size' 价格为 100
标签: javascript jquery socket.io