简体   繁体   English

以下拉格式显示Sharepoint列表数据

[英]Display Sharepoint list data in Dropdown format

I am calling a Sharepoint URL (GET) and retriving the column information. 我正在调用Sharepoint URL(GET)并检索列信息。 I have column names like First Name (eg Donald), Last Name (eg Duck), etc in the list. 我在列表中有列名,例如名字 (例如唐纳德), 姓氏 (例如鸭子)等。 Now I have to concat First Name & Last Name (Donald Duck) and to display this in form of a dropdown list. 现在,我必须合并名和姓(唐老鸭),并以下拉列表的形式显示它。 I am writing the below piece of code to get the shareopint response (XML): 我正在编写以下代码来获取shareopint响应(XML):

 $.ajax({ type: "GET", beforeSend: function(xhr) { xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ":" + password)); }, url: calURL, crossDomain: true, //dataType: "xml", //cache: false, processData: false, xhrFields: { withCredentials: true }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); document.getElementById("demo").innerHTML = "Got stuck"; }, success: function(xml) { var xmlArr = []; var html_text = null; alert($(xml).find('entry').text()); $(xml).find('entry').each(function(){ var title = $(this).find('title').text(); var firstName = $(this).find('First Name').text(); var familyName = $(this).find('Family Name').text(); var fullName = title + firstName + familyName; }); }, }); 
However, the above is not reading the values from the response. 但是,上面没有从响应中读取值。 And also how can i convert this into a dropdown in the HTML page? 还有如何将其转换为HTML页面中的下拉列表? Thanks. 谢谢。

You have not provided your SharePoint response XML, but the information you want are most likely to be in the row element attributes rather than in their text content. 您尚未提供SharePoint响应XML,但是所需信息很可能在行元素attributes而不是在其text内容中。 Moreover every element in this xml has a namespace which should be referenced. 此外,此xml中的每个元素都有一个应引用的名称空间。

A sample XML: XML示例:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
     xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
     xmlns:rs="urn:schemas-microsoft-com:rowset" 
     xmlns:z="#RowsetSchema"> 

      <s:Schema id="RowsetSchema"> 
        <s:ElementType name="row"> 
          <s:AttributeType name="CustomerID" rs:number="1" rs:keycolumn="true"> 
            <s:datatype dt:type="int" dt:maxLength="4"/> 
          </s:AttributeType>
          <s:AttributeType name="Title" rs:number="2"> 
            <s:datatype dt:type="string" dt:maxLength="5" /> 
          </s:AttributeType>
          <s:AttributeType name="FirstName" rs:number="3"> 
            <s:datatype dt:type="string" dt:maxLength="15" /> 
          </s:AttributeType> 
          <s:AttributeType name="LastName" rs:number="4"> 
            <s:datatype dt:type="string" dt:maxLength="15"/> 
          </s:AttributeType> 
        </s:ElementType> 
      </s:Schema> 

      <rs:data> 
        <z:row CustomerID="123" Title="Mr."  FirstName="Donald" LastName="Duck"/> 
        <z:row CustomerID="456" Title="Mrs." FirstName="Minney" LastName="Mouse"/> 
        <z:row CustomerID="789" Title="Mr."  FirstName="Stuart" LastName="Little"/> 
      </rs:data> 
</xml>

If your response XML is like something above, change the ajax success handler to 如果您的响应XML类似于上述内容,请将ajax成功处理程序更改为

success: function(xml) { 
    $("rs\\:data", xml).find("z\\:row").each(function() {
        var id = $(this).attr('CustomerID');
        var title = $(this).attr('Title');
        var firstName = $(this).attr('FirstName');
        var lastName = $(this).attr('LastName');
        var fullName = title + firstName + lastName;
        // Add this as an option to <select id="customers"> dropdown list
        var option = '<option value="' + id + '">' + fullName + '</option>';
        $("#customers").append(option);
    });
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM