简体   繁体   English

使用SPServices GetListItems写入列数据

[英]Writing column data with SPServices GetListItems

I'm trying to pull information from a list in SharePoint using SPServices (a jQuery library). 我正在尝试使用SPServices(一个jQuery库)从SharePoint中的列表中提取信息。 I'm able to access the list just fine with the GetListItems operation but I'm having trouble pulling the values from the columns. 我可以使用GetListItems操作访问列表,但无法从列中提取值。 Basically, in it's simplest form, I have a column called 'Title' and I want to print a list of all the values in that column. 基本上,以最简单的形式,我有一列称为“标题”,我想打印该列中所有值的列表。 Below is my code, I'm not sure what I need to pull from 'x' and the documentation on codeplex isn't very thorough. 下面是我的代码,我不确定我需要从“ x”中提取什么,并且关于Codeplex的文档不是很详尽。 I've checked quite a few other threads but none seemed to solve this issue. 我检查了很多其他线程,但似乎没有一个可以解决此问题。 Any help would be wonderful. 任何帮助都会很棒。

    $().SPServices({
    operation:"GetListItems",
    async: false,
    listName: "Retention Test List",
    completefunc: function(xData, Status){
        //alert(xData.responseText);
        x = $(xData.responseXML).SPFilterNode("z:row")
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            document.write(x.innerHTML);


});
}
});

Surprised you didn't get an answer. 感到惊讶的是您没有得到答案。 The key is to get the element you want using $(this).attr("ows_[My Column Name]"). 关键是使用$(this).attr(“ ows_ [我的列名]”)获得所需的元素。 You will need to find the real names eg ows_Title or ows_A_x0020_Space 您将需要找到真实姓名,例如ows_Titleows_A_x0020_Space

In code fragments you can also use: 在代码片段中,您还可以使用:

XmlConvert.EncodeName = converts all the special characters to equivalent _x00xx_
XmlConvert.DecodeName = converts all the _x00xx_ back to the special characters.

Quickly get the correct name to use in your code: Edit list settings, click on the column use the name as shown in the URL. 快速获得要在代码中使用的正确名称:编辑列表设置,单击该列,使用URL中显示的名称。 Example : Field=A%5Fx0020%5FSpace . 示例:Field = A%5Fx0020%5FSpace。 for "A Space" 对于“一个空间”

    $(document).ready(function() {

    $().SPServices({
        operation: "GetListItems",
        listName: "Retention Test List",
        completefunc: function(xData, Status) {
            var seeMe = ""; 
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                seeMe += $(this).attr("ows_Title") + "<br/>";
            });
            $('.showme').html(seeMe); // or alert(seeMe); if so set "<br/>" to "<\n>"
        }
    });
});

HTH HTH

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

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