Using superagent package in nodejs, I'm not sure about what I can do in .end().
I'm trying to alter the values of 'title' and 'description' after getting data in 'get' function, but they remains the same.
Also when I tried to return the data.body[0].title in .end(), then
var todo = new Todo();
console.log(todo.get());
it said it's undefined. How do I change the value of Todo's properties with superagent syntax?
Code as below:
function Todo() {
this.title = "milk";
this.description = "ok, Milk is a white liquid produced by the mammary glands of mammals.";
}
util.inherits(Todo, Model);
Todo.prototype.get = function() {
console.log(this.title);
request
.get(this.read().origin + '/todos/11' + '?userId=1&accessToken=' + this.read().accessToken)
.send({
username : 'jiayang',
password : 'password',
clientId : this.read().clientId,
clientSecret : this.read().clientSecret
})
.end(function(data) {
console.log(data.body[0]);
this.title = data.body[0].title;
this.description = data.body[0].description;
});
};