0

我正在尝试使用 JavaScript 检索列表数据。但是出了点问题。我正在尝试调试代码,但我无法理解那件事。
以下是 JavaScript 代码:

ExecuteOrDelayUntilScriptLoaded(PopulateDepartments, "sp.js");
var _ctx = null;
var _web = null;
var _allItems = null;

function PopulateDepartments() {
    debugger;
    _ctx = SP.ClientContext.get_current();
    _web = _ctx.get_web();
    var list = _web.get_lists().getByTitle("ServiceType");
    var query = new SP.CamlQuery();
    query.set_viewXml("<View><Query><OrderBy><FieldRef Name='Title'/></OrderBy></Query></View>");
    _allItems = list.getItems(query);
    _ctx.load(_allItems, 'Include(Title,ID)');
    debugger;
    _ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess),
        Function.createDelegate(this, this.PopulateDepartmentFaild));
}

function PopulateDepartmentSuccess() {
    var ddlEntry = this.document.getElementById("ddl1");
    ddlEntry.options.length = 0;
    var listEnumerator = _allItems.getEnumerator();
    while (listEnumerator.moveNext()) {
        var currentItem = listEnumerator.get_current();
        ddlEntry.options[ddlEntry.options.length] = new Option(currentItem.get_item("Title"), currentItem.get_item("ID"));
    }
}

function PopulateDepartmentFaild() {
    alert("Something went Wrong....!!");
}

每当我运行此代码时,它都会显示警报框。
请帮忙..

4

2 回答 2

2

有时 this 不采用正确的引用。检查它是否适用于删除此引用 .so 而不是这个 _ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess), Function.createDelegate(this, this.PopulateDepartmentFaild ));

尝试使用这样的东西

_ctx.executeQueryAsync(PopulateDepartmentSuccess,PopulateDepartmentFaild);

于 2014-05-13T09:19:34.217 回答
0

我认为。如果您创建 Sharepoint App,则需要在 AppManifest.xml 中授予 web 权限。

于 2016-10-24T07:27:25.267 回答