我正在尝试将从func1中的服务器检索到的数据对象作为参数传递给func2,但不能按我的意愿工作,请参阅代码:
var MyView = Backbone.View.extend({
el: $("#page"),
events: {
"click #button1" : "func1",
"click #button2" : "func2"
},
......................,
func1: function(){
var registData = {myData: "123"};
// post registData to server
$.post('/', registData, function(data){
// server response with a data
this.func2(data);
},
func2: function(data){
console.log(data);
}
})
答案 0 :(得分:2)
this
不是定义func2
的对象。
你可以这样做:
func1: function(){
var that = this;
var registData = {myData: "123"};
// post registData to server
$.post('/', registData, function(data){
// server response with a data
that.func2(data);
});
},