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);

        }
    });
});

上記のコードは node にあります。以下はクライアントの 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 ");
    }

})

ありがとう

4

1 に答える 1

0

答えを得た

送る代わりに

         res.send(result);

次のように送信します。

         res.send(result[0]);

その後、結果は問題ありません!

于 2012-04-18T05:44:24.943 に答える