如何使用JQuery或JavaScript和Fill DropDownList检索sharepoint 2013列表数据? [英] How to retrieve sharepoint 2013 list data using JQuery or JavaScript and Fill DropDownList?

查看:136
本文介绍了如何使用JQuery或JavaScript和Fill DropDownList检索sharepoint 2013列表数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to retrieve list data using JavaScript. But something goes wrong. I am trying to debug the code but I am not able to understand that thing.
Following is the JavaScript Code:

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....!!");
}

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

Whenever I run this code it shows me alert box.
Please Help..

推荐答案

有些时候,它没有正确的引用.请检查它是否可以删除该引用. _ctx.executeQueryAsync(Function.createDelegate(this,this.PopulateDepartmentSuccess), Function.createDelegate(this,this.PopulateDepartmentFaild));

There are times when this doesn't takes the correct reference.Check if it works with removing this reference .so Instead of this _ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess), Function.createDelegate(this, this.PopulateDepartmentFaild));

尝试使用类似的东西

_ctx.executeQueryAsync(PopulateDepartmentSuccess,PopulateDepartmentFaild);

_ctx.executeQueryAsync(PopulateDepartmentSuccess,PopulateDepartmentFaild);

这篇关于如何使用JQuery或JavaScript和Fill DropDownList检索sharepoint 2013列表数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆