如何在nodejs中使用superagent语法更改值属性?

在nodejs中使用superagent包,我不知道我能在.end()中做什么。

在“get”函数中获取数据之后,我试图改变“标题”和“描述”的值,但它们保持不变。

另外,当我试图返回.end()中的data.body [0] .title,然后

var todo = new Todo(); console.log(todo.get()); 

它说这是不确定的。 如何使用superagent语法更改Todo属性的值?

代码如下:

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

callback函数的本地作用域是callback函数的上下文。

尝试;

 Todo.prototype.get = function() { var self = this; 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]); self.title = data.body[0].title; self.description = data.body[0].description; }); };