我有以下代码:
function doDialogAjax(link: Link. modal: Modal) {
$.ajax( link.Url,
{
cache: false,
dataType: 'html'
})
.done(onDialogDone)
.fail(onDialogFail);
}
function onDialogDone(data: any, textStatus: string, jqXHR: JQueryXHR) {
var x = data;
// I need to access link.abc and modal.def properties here
}
如何将链接对象发送到我的 onDialogDone() 函数?我 似乎记得有一些方法可以发送指定的上下文信息对象,但我找不到任何这样的例子。
最佳答案
您可以使用上下文键来更改回调中 this
的值:
function doDialogAjax(link: Link. modal: Modal) {
$.ajax( link.Url,
{
cache: false,
dataType: 'html',
context: {
link: link,
modal: modal
}
})
.done(onDialogDone)
.fail(onDialogFail);
}
function onDialogDone(data: any, textStatus: string, jqXHR: JQueryXHR) {
var x = data;
// this refers to the context-object, with keys [link, modal]
console.log(this.link);
console.log(this.modal)
}
关于javascript - 如何将对象的副本传递给 $.ajax 的 .done() 中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343557/