从asp:RadioButtonList中的sharepoint列表设置项目标题

问题描述 投票:0回答:1

这是我关于Stack Overflow的第一个问题。

我正在SharePoint中开发一个解决方案,我有一个包含多个项目的列表,我需要获取这些项目的标题并将它们插入到RadioButtonList中,以便在添加新项目时,单选按钮可以采用新物品。谢谢!

尝试以DropDownList的方式做,但它不起作用...

function loadDdl(ddlId, list) {
    var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
    $.ajax({
        url: siteUrl + "/_api/web/lists/GetByTitle('" + list + "')/items",
        type: "GET",

        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            $.each(data.d.results, function (key, value) {
                $("#" + ddlId).append($("<option></option>")
                                .val(value.Title)
                                .html(value.Title));
            });

            sortDropDownListByText();
        },
        error: function (error) {
            alert(JSON.stringify(error));
            loadingOff();
        }
    });
}

将项目插入DDL:

$(document).ready(function () {
    // SP.SOD.executeFunc('sp.js', 'SP.ClientContext', initializePage());
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', revisarPermisos);
    var emitidoPor = _spPageContextInfo.userDisplayName;
    $("#lblEmitidoPor").append(emitidoPor);
    loadDdl("ctl00_PlaceHolderMain_ddlEmisor", "Departamentos");
    loadDdl("ctl00_PlaceHolderMain_ddlDepartamentoDeHallazgo", "Departamentos");
    loadDdl("ctl00_PlaceHolderMain_accionesRdl", "Departamentos");

    $("#hlNuevaSolicitud").addClass("active");
    loadingOff();
});
javascript jquery html sharepoint
1个回答
0
投票

这是解决方案,以及如何在RadioButtonList中插入列表项

function loadRbl(RblId, lista) {

var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
$.ajax({
    url: siteUrl + "/_api/web/lists/GetByTitle('" + lista + "')/items",
    type: "GET",

    headers: {
        "accept": "application/json;odata=verbose",
    },

    success: function (data) {
        var i = 1;
        $.each(data.d.results, function (key, value) {
            $("#" + RblId).append($("<tr><td>"
                + "<input type='radio' id='" + RblId + i+ "' 
               name='ctl00$PlaceHolderMain$rdlAccion' value='" + value.Title 
               + "'>"
               + "<label for='" + RblId + i+"'>" + value.Title + "</label>"
               + "</td></tr>"));
               i++;

        });



    },
    error: function (error) {
        alert(JSON.stringify(error));
        loadingOff();
    }
});

}
© www.soinside.com 2019 - 2024. All rights reserved.