我需要从一个用户的所有交易中的所有股票中恢复 towerjs(与 mongodb 商店)报价股票。这段代码不起作用,while循环没有停止,但我不明白为什么
App.Trade.where(userId: @currentUser.get('id')).order("date", "desc").all (error, trades) ->
idst = {}
i = 0
len = trades.length
while i < len
trade = trades[i]
idst[trade.get('stockTicker')] = 1 if trade.get('stockId') and not idst[trade.get('stockId')]
i++
App.Stock.where({ticker: {$in: Object.keys(idst)}}).all (error, stocks) ->
map = {}
mapQuote = {}
i = 0
len = stocks.length
while i < len
stock = stocks[i]
map[stock.get('ticker')] = stock
App.QuoteStock.where(ticker: stock.get('ticker')).order("createdAt", "desc").limit(1).first (error, quoteStock) ->
mapQuote[stock.get('ticker')] = quoteStock
i++
i = 0
len = trades.length
while i < len
trade = trades[i]
trade.stock = map[trade.get('stockTicker')]
trade.quoteStock = mapQuote[trade.get('stockTicker')]
i++
_this.trades = trades