我有这段 TypeScript 代码:
module MyPage {
export class MyVm {
ToDo : string;
Load() {
//can access todo here by using this:
this.ToDo = "test";
$.get("GetUrl", function (servertodos) {
//but how do I get to Todo here??
this.ToDo(servertodos); //WRONG ToDo..
});
}
}
}
问题是,我如何在$.get回调函数中访问todo成员字段?
data
参数被命名为todos
,因为这是调用提供的数据类型。如果您愿意,可以在上面的示例中使用data
代替todos
。todos
参数将包含jQuery传递给回调函数的数据对象。 - Fenton