Javascript 如何告诉延迟对象需要完成哪些代码才能触发承诺中的.done()?

Javascript 如何告诉延迟对象需要完成哪些代码才能触发承诺中的.done()?,javascript,jquery,Javascript,Jquery,我正在努力实现我自己的承诺。我看到的所有教程都“解决”了与jquery调用相关联的回调中的延迟问题。例如,在本例中,行dfd.resolve(“完成淡出!”)似乎将延迟对象绑定到动画方法。这就是“解决”延迟对象的含义吗?我很抱歉,它似乎没有像那样接受函数回调。如何将此代码包装成承诺 function respondToSearch(){ var dfd = new $.Deferred(); //I want promise.done to fire when this has

我正在努力实现我自己的承诺。我看到的所有教程都“解决”了与jquery调用相关联的回调中的延迟问题。例如,在本例中,行
dfd.resolve(“完成淡出!”)似乎将延迟对象绑定到动画方法。这就是“解决”延迟对象的含义吗?我很抱歉,它似乎没有像那样接受函数回调。如何将此代码包装成承诺

function respondToSearch(){
    var dfd = new $.Deferred();
    //I want promise.done to fire when this has finished. how do I glue this code to the deferred?
    dc.embed.load('http://www.documentcloud.org/search/embed/', {some json}); 
    return dfd.promise();
}      
试试这个:

function respondToSearch(){
    var dfd = new $.Deferred();

    dc.embed.load('http://www.documentcloud.org/search/embed/', {some json}, function() {
        // This is where you would tell the promise it should be resolved or failed, etc.
        // in which case, the promise's "done" callbacks will be fired
        dfd.resolve();
    }); 

    return dfd.promise();
}  

编辑:假设如OP所述,dc.embed.load()是$.fn.load()

dc.embed.load是什么?仅仅是jQuery的
$.fn.load
?@minitech似乎就是这样。或者至少我可以打个电话回去,这非常有帮助。谢谢