jQuery延迟并承诺-错误:对象不支持属性或方法'then' [英] jQuery Deferred and promise - Error: Object doesn't support property or method 'then'
问题描述
我可能在这里错过了一些非常基本的东西,但是我似乎找不到错误,并且变得越来越令人沮丧.我只是想从我的开发SharePoint网站中提取列表(然后是项目,但一次只能提取一件事).
I'm probably missing something really basic here but I can't seem to find the error and it's getting frustrating. I'm just trying to pull the lists (and then items, but one thing at a time here) from my dev SharePoint site.
我已经构建了第一个延迟方法,并且控制台日志显示该方法已完成,但是随后出现错误:对象不支持属性或方法'then'",就好像jQuery失败一样.
I've got the first deferred method built and the console log shows that it completes, but then I get "Error: Object doesn't support property or method 'then'" as though jQuery is failing somehow.
For reference I'm trying to follow the method described here: http://www.shillier.com/archive/2013/03/04/using-promises-with-the-javascript-client-object-model-in-sharepoint-2013.aspx
这是代码:
<script src="jquery-1.11.2.js"></script>
<script type="text/javascript">
$(function () {
GetSiteLists.bListsGotten().then(
function (oWebLists) {
// Get Lists Succeeded
alert('Lists Retrieved');
}
, function (sender, args) {
// Get Lists Failed
alert('Lists Not Retrieved');
}
);
});
GetSiteLists = function () {
var bListsGotten = function () {
var deferred = $.Deferred();
var oContext = new SP.ClientContext.get_current();
console.log('oContext instantiated');
var oWeb = oContext.get_web();
console.log('oWeb instantiated');
this.oWebLists = oWeb.get_lists();
console.log('oWebLists command set');
oContext.load(this.oWebLists);
console.log('context load command set');
oContext.executeQueryAsync(
Function.createDelegate(this,
function () { deferred.resolve(this.oWebLists); }),
Function.createDelegate(this,
function (sender, args) { deferred.reject(sender, args); }));
console.log('list retrieval query executed async');
console.log('returning promise');
return deferred.promise;
}
return {
bListsGotten: bListsGotten
}
}();
</script>
推荐答案
promise
是一个函数,您没有在调用它.
promise
is a function and you're not calling it.
return deferred.promise()
将解决该问题.
这篇关于jQuery延迟并承诺-错误:对象不支持属性或方法'then'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!