gpt4 book ai didi

javascript - 如何从 jQuery 延迟传递参数

转载 作者:行者123 更新时间:2023-11-28 20:27:34 25 4
gpt4 key购买 nike

我有一个 Backbone 模型,可以获取一些数据,处理数据,然后函数应该获取处理后的数据。

$.when(model.fetch())
.done(function(){
return model.processData()
})
.then(function(processedData){
//make something with the processed data
})

不幸的是then方法从 model.fetch() 获取结果调用而不是 done 的返回值功能

最佳答案

您必须使用.then而不是.done.then 返回一个新的 Promise,该 Promise 使用回调函数返回的值进行解析。

另一方面,

.done 返回原始的 Promise 对象,并且回调的返回值将被忽略。

更多信息可以在documentation中找到(强调我的):

As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated deferred.pipe() method. The doneFilter and failFilter functions filter the original deferred's resolved / rejected status and values. The progressFilter function filters any calls to the original deferred's notify or notifyWith methods. These filter functions can return a new value to be passed along to the promise's .done() or .fail() callbacks, or they can return another observable object (Deferred, Promise, etc) which will pass its resolved / rejected status and values to the promise's callbacks. If the filter function used is null, or not specified, the promise will be resolved or rejected with the same values as the original.

关于javascript - 如何从 jQuery 延迟传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17083532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com