【发布时间】:2014-02-27 06:24:19
【问题描述】:
我有一个相当深的内存数据库,我想,我已经找到了代码的最佳实现,如果有人有更好的方法在 lodash 中执行双 forEach 循环,或者我以某种方式错误地使用它会很高兴知道。
对象:
smallDB = {
user1:{
permissions:[],
locations:[
{ip:'0.0.0.0',messages:[]},
{ip:'',messages:[]}
]
},
user2:{
permissions:[],
locations:[
{ip:'0.0.0.0',messages:[]},
{ip:'0.0.1.0',messages:[{mid:'a unique id','user':'the sender',message:'the text of the message'}]}
]
}
}
发送我使用的消息:
ld.forEach smallDB, (a)->
ld.forEach a.locations, (b)->
b.messages.push {mid,user,message}
我只是想确保这是向 smallDB 中的所有用户及其所有位置的所有用户添加消息到迷你数据库的最佳方式
【问题讨论】:
标签: node.js object coffeescript performance lodash