我需要在towerjs(帶有mongodb商店)中的一個用戶的所有交易中的所有股票報價股票中恢復。 此代碼不工作,while循環不停止,但我不明白爲什麼與Towerjs(咖啡和mongodb)的關係模型
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
「哪裏」異步? –
是的,哪裏是異步的。 –
在技術上,'all'和'first'是異步的,'where'只是建立查詢。 –