如何使用JQuery或JavaScript和Fill DropDownList检索sharepoint 2013列表数据

How to retrieve sharepoint 2013 list data using JQuery or JavaScript and Fill DropDownList?

本文关键字:sharepoint 检索 2013 列表 数据 DropDownList Fill JQuery 何使用 JavaScript      更新时间:2023-09-26

我正在尝试使用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....!!");
}

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

有时这不会得到正确的引用。检查它是否能删除此引用。因此,不要这样_ctx.executeQueryAsync(Function.createDelegate(this,this.PopulateDocumentSuccess),Function.createDelegate(this,this.PopulateDocumentFaild);

尝试使用类似的东西

_ctx.executeQueryAsync(填充部门成功,填充部门失败);

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