简体   繁体   English

使用CAML,如何将两个不同的列表项绑定到Sharepoint上的一个下拉列表?

[英]Using CAML, how can I bind two different list items to the one dropdown list on Sharepoint?

I so far successfully bind one to a dropdown but can't figure out how to add the next data item (called "text") 到目前为止,我已经成功地将一个绑定到一个下拉列表,但无法弄清楚如何添加下一个数据项(称为“文本”)

  function loadCombo(context) {
        list = context.get_web().get_lists().getByTitle('HRC');
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml("<Query><Where></Where></Query>");

        listItems = list.getItems(camlQuery);
        context.load(listItems);
        context.executeQueryAsync(appendData, loadFailed);
    }

    function appendData(sender, args) {
        var enumerator = listItems.getEnumerator();
        while (enumerator.moveNext()) {
            var item = enumerator.get_current();
            $("#country1").append($('<option></option>').val(item.get_id()).html(item.get_item('Title')));

        }
    }

    function loadFailed(sender, args) {
        alert('list failed to load: ' + args.get_message());
    }
    $(document).ready(function() {
        var context = new SP.ClientContext.get_current();
        loadCombo(context);
    });

I Have modified your code.try this. 我已经修改了您的代码。

function loadCombo(context,listname) {
    list = context.get_web().get_lists().getByTitle(listname);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<Query><Where></Where></Query>");

    listItems = list.getItems(camlQuery);
    context.load(listItems);
    context.executeQueryAsync(appendData, loadFailed);
}

function appendData(sender, args) {
    var enumerator = listItems.getEnumerator();
    while (enumerator.moveNext()) {
        var item = enumerator.get_current();
        $("#country1").append($('<option></option>').val(item.get_item('Title')).html(item.get_item('Title')));

    }
}

function loadFailed(sender, args) {
    alert('list failed to load: ' + args.get_message());
}
$(document).ready(function() {
    var context = new SP.ClientContext.get_current();
    loadCombo(context,'HRC');
    loadCombo(context,'XYZ');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Knockout.js将项目列表绑定到下拉列表 - knockoutjs bind list of items to dropdown 在下拉列表中单击列表中的值时,如何使用Sharepoint上的Knockout进行划分? - How can I, using Knockout on Sharepoint, have a div visable when a value from a list is clicked on a dropdown? 我如何使用jQuery绑定下拉列表 - how do i bind dropdown list using jquery 如何使用AJAX成功更新共享点列表上的多个项目? - How can I succesfully update multiple items on a sharepoint list using AJAX? 如何针对存储在Sharepoint 2013列表中的下拉列表检查HTML下拉列表? - How can I check a HTML dropdown against a dropdown stored in a Sharepoint 2013 list? 在下拉菜单中使用JavaScript检索SharePoint列表项 - Retrieve SharePoint list items with Javascript in a dropdown menu jQuery:如何在不同列表中的相同位置选择两个列表项? - jQuery: How can I select two list items in the same position in different lists? 下拉列表显示使用CAML SOAP Ajax JQuery方法的SharePoint列表中的数据 - Drop down list showing data from a SharePoint List using CAML SOAP Ajax JQuery methodology 我如何匹配两个下拉列表中的数据 - how can i match data from two dropdown list 使用 caml 查询获取列表项休息呼叫 - Get list items rest call with caml query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM