从 Sharepoint 列表中填充下拉列表

发布于 2024-10-15 11:19:22 字数 205 浏览 1 评论 0原文

我正在尝试根据 Sharepoint 列表中的信息动态填充下拉列表。我知道我可以将列表添加到页面并隐藏它,但我想要的是使用客户端脚本语言填充列表,并且当前页面上不存在该列表。我假设采用 ajx 方法,但不确定如何实现这一点。我被限制没有 SP Designer 或 Visual Studio。那么这可以使用 Web 部件或带有客户端脚本代码/ajax 的简单内容编辑器来完成。如果是这样怎么办?

I am trying to dynamically populate a dropdown list based on the information in a Sharepoint list. I know I can add the list to the page and hide it, but what I want is to populate the list using client scripting language and not have the list exist on the current page. I assume an ajx approach, but not sure how to accomplish this. I am restricted to not having SP Designer or Visual Studio. So can this be accomplished using a webpart or a simple content editer with client scripting code/ajax. If so how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

可是我不能没有你 2024-10-22 11:19:22

查看 功能区自定义 - 下拉控件、客户端对象模型和JavaScript 页面组件。许多代码都是针对功能区的,但 loadCurrentWebLists 和 getDropdownItemsXml 演示了您想要执行的操作。您还可以查看 SharePoint 2010:使用 ECMAScript操作(添加/删除/更新/获取)列表项OM模型Javascript。这些处理列表项,但您应该能够针对列表调整它们。

Take a look at Ribbon customizations - dropdown controls, Client Object Model and JavaScript Page Components. A lot of the code is for the Ribbon, but the loadCurrentWebLists and getDropdownItemsXml demonstrate what you are trying to do. You can also look at SharePoint 2010: Use ECMAScript to manipulate (Add/Delete/Update/Get) List Items and OM model Javascript. These deal with List Items, but you should be able to adapt them for Lists.

赴月观长安 2024-10-22 11:19:22

您可以尝试 SPServices 库吗2007 年?

Can you try the SPServices library for 2007?

冷心人i 2024-10-22 11:19:22

以下是我如何将其用于用户信息列表,该列表是有权访问该站点的所有用户的列表。 select: function(e, ui){} 是当您从自动完成框中选择某些内容时调用的函数。

<link href="../css/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/jquery.SPServices-0.5.8.js"></script>

<script type="text/javascript">
$(document).ready (function() {
    $().SPServices({
        operation: "GetListItems",
        async: true,
        listName: "User Information List",
        CAMLViewFields: "<ViewFields>" +
            "<FieldRef Name='Title' />" +
            "<FieldRef Name='MobilePhone' />" +
            "<FieldRef Name='Picture' />" +
            "<FieldRef Name='SPSResponsibility' />" +
            "<FieldRef Name='Name' />" +
            "</ViewFields>",
        completefunc: AttachMembersAutoComplete
    });
});

function AttachMembersAutoComplete(xmlResponse) {
    var domElementArray = $( "[nodeName=z:row]", xmlResponse.responseXML );

    var dataMap = domElementArray.map(function() {
        return {
            value: $(this).attr('ows_Title'),
            mobile: $(this).attr('ows_MobilePhone'),
            picture: $(this).attr('ows_Picture'),
            askmeabout: $(this).attr('ows_SPSResponsibility'),
            name: $(this).attr('ows_Name')
        };
    });

    var data = dataMap.get();

    $("input#inputMembersAutoComplete").autocomplete({
        source: data,
        select: function(e, ui){

            window.alert(ui.item['askmeabout'] + "\n" + ui.item['name']);

            if(ui.item['picture'] != undefined) {
                var tmpPicture = ui.item['picture'];
                var commaIndex = tmpPicture.indexOf(',');
                tmpPicture = tmpPicture.substr(0,commaIndex);
            }else{
                var tmpPicture = "/_layouts/images/person.gif";
            }

            var tmpHTML = "<div>";
            tmpHTML += "<a href='/Person.aspx?accountname=" + ui.item['name'] + "' >";
            tmpHTML += "<p>"+ ui.item['value'] + "  " + ui.item['mobile'] + "</p>";
            tmpHTML += "</a>";
            tmpHTML += "<img src='"+ tmpPicture + "' />";
            tmpHTML += "</div>";

            $("#person_info").html(tmpHTML);
        }
    });
}
</script>

Here is how i use it for the user information list which is the list of all users with permissions to that site. The select: function(e, ui){} is the function which is called when you select something from the autocomplete box.

<link href="../css/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/jquery.SPServices-0.5.8.js"></script>

<script type="text/javascript">
$(document).ready (function() {
    $().SPServices({
        operation: "GetListItems",
        async: true,
        listName: "User Information List",
        CAMLViewFields: "<ViewFields>" +
            "<FieldRef Name='Title' />" +
            "<FieldRef Name='MobilePhone' />" +
            "<FieldRef Name='Picture' />" +
            "<FieldRef Name='SPSResponsibility' />" +
            "<FieldRef Name='Name' />" +
            "</ViewFields>",
        completefunc: AttachMembersAutoComplete
    });
});

function AttachMembersAutoComplete(xmlResponse) {
    var domElementArray = $( "[nodeName=z:row]", xmlResponse.responseXML );

    var dataMap = domElementArray.map(function() {
        return {
            value: $(this).attr('ows_Title'),
            mobile: $(this).attr('ows_MobilePhone'),
            picture: $(this).attr('ows_Picture'),
            askmeabout: $(this).attr('ows_SPSResponsibility'),
            name: $(this).attr('ows_Name')
        };
    });

    var data = dataMap.get();

    $("input#inputMembersAutoComplete").autocomplete({
        source: data,
        select: function(e, ui){

            window.alert(ui.item['askmeabout'] + "\n" + ui.item['name']);

            if(ui.item['picture'] != undefined) {
                var tmpPicture = ui.item['picture'];
                var commaIndex = tmpPicture.indexOf(',');
                tmpPicture = tmpPicture.substr(0,commaIndex);
            }else{
                var tmpPicture = "/_layouts/images/person.gif";
            }

            var tmpHTML = "<div>";
            tmpHTML += "<a href='/Person.aspx?accountname=" + ui.item['name'] + "' >";
            tmpHTML += "<p>"+ ui.item['value'] + "  " + ui.item['mobile'] + "</p>";
            tmpHTML += "</a>";
            tmpHTML += "<img src='"+ tmpPicture + "' />";
            tmpHTML += "</div>";

            $("#person_info").html(tmpHTML);
        }
    });
}
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文