以下代码未按我的预期工作:
jQuery.get("/api/resource/1")
.then(function(res){ return res.length; })
.then(function(res){ var length = res; });
我认为 length
会从上面的函数中获取返回的 length 属性的值,但事实并非如此。 res的值不会被锁链。但如果我在 dojo 中编写这段代码,它就会像我预测的那样工作:
dojo.xhrGet({url:"/api/resource/1"})
.then(function(res){ return res.length; })
.then(function(res){ var length = res; });
我应该怎样做才能让 jQuery 按照我想要的方式工作?
最佳答案
我想你想要deferred.pipe .
关于jquery - 我缺少什么? jQuery 和 Dojo 中的链接 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9807810/