【发布时间】:2015-02-27 16:44:58
【问题描述】:
我正在尝试从 SPService SPGetListItemsJson 获取我的承诺项目。问题是,当 SPGetListItemsJson 被调用并且 requestPromise 完成并且延迟被解决时,我希望数据能够传递到我在 populateDropDownControlWithList 中的匿名函数,但它是未定义的。
function populateDropDownControlWithList(option, control, addSelectValue)
{
if (typeof (addSelectValue) === 'undefined')
{
addSelectValue = false;
}
var selectedIndex = control.val() ? control.val() : -1;
if (addSelectValue)
{
control.append('<option value=-1>Select an Option</option>');
}
var request = SPGetListItemsJson(option);
request.done(function (data) // Expect the json object here but it is undefined
{
$.each(data, function ()
{
controlappend('<option value=' + this.Id + '>' + this.Title + '</option>');
});
});
}
function SPGetListItemsJson(option)
{
var deferred = $.Deferred();
var requestsPromise = $().SPServices.SPGetListItemsJson({
listName: option.Name,
CAMLQuery: option.Query,
CAMLViewFields: option.View,
mappingOverrides: option.Mapping,
debug: option.Debug,
async: option.async
});
requestsPromise.done(function ()
{
deferred.resolveWith(this.data); // Verified this.data is populated with the correct result
});
return deferred.promise();
}
任何帮助将不胜感激!
【问题讨论】:
标签: jquery jquery-deferred spservices