Backbone,Node : when i call fetch method, fetch is successful in server but when it sends response back using
res.send(result)
it is not sending(may be) any model or it is sending old model back,and it is sending only response object . Model is what i want, how can i get ?
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);
}
});
});
the above code is in node . Below one is in client javascript (in a view).
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 ");
}
})
thanks
got the answer
instead of sending
res.send(result);
send like this :
res.send(result[0]);
then the result will be fine !