2012-04-17 42 views
1

骨幹,節點:當我打電話取方法,取是成功的服務器,但是當將其發送迴響應使用骨幹節點 - 獲取 - 服務器只發送響應對象但不是模型,我如何獲取模型?

res.send(result) 

它不發送(而定)的任何模型或它正在發送舊模式後面,並且它只發送響應對象。模型是我想要的,我怎麼能得到?

app.get('/college/colleges/:_id', function (req, res) { 

    oid = new ObjectID(req.params._id.toString()); 
    return CollegeModel.find({ 
     _id: oid 
    }, function (err, result) { 
     if (!err) { 
      console.log("Fetched college model successfully"); 
      res.send(result); 
     } else { 

      console.log("Error : " + err); 
      res.send(err); 

     } 
    }); 
}); 

上面的代碼在節點中。下面的一個是在客戶端JavaScript(在視圖中)。

college_model = new CollegeModel(id) 
college_model.fetch({ 
    success = function (model, res, options) { 
     console.log model // here , new model should come with all new attributes, but old model with only id attribute is appearing here,,,in model format. 
     console.log res // here, i am getting all required records in objectformat,no problem for this res 
    } 
    error = function (model, res, options) { 
     console.log("Error "); 
    } 

}) 

感謝

回答

0

了,而不是發送

  res.send(result); 

答案

發送這樣的:

  res.send(result[0]); 

那麼結果將被罰款!