我正在尝试使用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....!!");
}
每当我运行此代码时,它会显示警报框 请帮助..
答案 0 :(得分:2)
有时候这没有采用正确的引用。检查它是否可以删除此引用.so而不是这个 _ctx.executeQueryAsync(Function.createDelegate(this,this.PopulateDepartmentSuccess), Function.createDelegate(this,this.PopulateDepartmentFaild));
尝试使用类似的东西
_ctx.executeQueryAsync(PopulateDepartmentSuccess,PopulateDepartmentFaild);
答案 1 :(得分:0)
我认为。如果您正在创建Sharepoint应用程序,则需要在AppManifest.xml中为Web授予权限。