将 SharePoint SOAP 与 jQuery GetListItems 结合使用 - 简单但无法解决! [英] Using SharePoint SOAP with jQuery GetListItems - Simple but can't work it out!

查看:12
本文介绍了将 SharePoint SOAP 与 jQuery GetListItems 结合使用 - 简单但无法解决!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 SharePoint 列表加载到无序列表中,以便我可以创建一个简单的搜索功能(Sharepoint 搜索非常糟糕).我借用和改编的代码如下:

I'm trying to load in a SharePoint list to a Unordered List so I can create a simple search function (the Sharepoint Search is just horrible). The code I have borrowed and adapted is below:

$(document).ready(function() {
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> 
                <soapenv:Body> 
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> 
                        <listName>Metric_Audit</listName> 
                        <viewFields> 
                            <ViewFields> 
                <FieldRef Name='ReportName' /> 
                <FieldRef Name='Metric Name' /> 
                           </ViewFields> 
                        </viewFields> 
                    </GetListItems> 
                </soapenv:Body> 
            </soapenv:Envelope>";

        $.ajax({
            url: "http://teamspace.intranet.group/sites/CSI/ID/DB/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: Result,
            contentType: "text/xml; charset="utf-8""
        });
    });


    function Result(xData, status) {
        $(xData.responseXML).find("z\:row").each(function() {
            var liHtml = "<li>" + $(this).attr("ows_ReportName") + "</li>";
            $("#MetricsUL").append(liHtml);
        });
    }
});

<ul id="MetricsUL"/> 

它按照它应该的方式填充列表,但所有项目都具有名称未定义".我尝试删除空格等但无济于事,当我将列表更改为任务"列表时,它工作正常.

It populates the list as it should but all the items have the name 'undefined'. I have tried removing spaces etc. to no avail and when I change the list to the 'tasks' list it works just fine.

一直盯着这个AGES.您可以建议的任何提示将不胜感激!我确定这是我无法解决的小事!

Been staring at this for AGES. Any tips you can suggest would be really appreciated! I'm sure it's something small that I just can't work out!

谢谢!

推荐答案

您是否确认引用了正确的字段名称?

Have you verified you're referencing the correct Field names?

您在 soapEnv 中定义的 CAML 查询需要使用字段的内部名称,而不是它们的显示名称.我保证 Metric Name 是不正确的;它可能类似于 Metric_x0020_Name 或类似内容.

The CAML query you've defined in soapEnv requires the use of the fields' internal names, not their display names. I guarantee Metric Name is not right; it's probably something like Metric_x0020_Name or similar.

如何确定字段的内部名称?有几种方法.

How do you determine the internal names of your fields? There's a couple of methods.

让我向您介绍一个名为 U2U CAML 查询生成器.这应该在每个 SharePoint 开发人员的工具箱中.启动它,将其指向正确的列表(如果您不在服务器上,则通过 SharePoint Web 服务连接),它将允许您使用字段的显示名称构建 CAML 查询,但生成正确的底层 CAML你.它也非常适合构建复杂的过滤器和布尔逻辑,此外,它还可以让您运行查询并获得即时反馈.

Let me introduce you to a great utility called U2U CAML Query Builder. This should be in every SharePoint developer's toolbox. Fire it up, point it at the right list (connect via SharePoint Web Service if you're not on the server), and it will allow you to build CAML queries using the display names of the fields, but generate the correct underlying CAML for you. It's also great for constructing complex filters and boolean logic, plus it lets you run the query and get immediate feedback.

获取字段名称的另一种方法是导航到列表设置,然后单击您感兴趣的字段的名称.检查您的 URL 并查找名为 &Field<的查询字符串参数/代码>;它会泄露字段的内部名称.如果您使用 Internet Explorer(一个简单的 在线解码器可以帮助破译该值),但如果您使用 Firefox,您将看到该值未编码.

Another approach to getting the field name is to navigate into the list settings, then click on the name of a field you're interested in. Check out your URL and look for the querystring parameter named &Field; it will divulge the internal name of the field. This value will be URL Encoded if you're using Internet Explorer (a simple online decoder can help decipher the value), but if you use Firefox, you'll see the value unencoded.

将正确的字段名称插入到您的 CAML 查询中,然后再试一次.

Plug the correct Field names into your CAML query and give it another whirl.

这篇关于将 SharePoint SOAP 与 jQuery GetListItems 结合使用 - 简单但无法解决!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆