javascript - 在 DIV 中显示来自 SharePoint 的 CAML 查询结果

标签 javascript sharepoint caml

所以我想做的是在带有一些自定义类的 div 中显示 SharePoint 列表中的一些内容。第一个脚本使用来自 Awkward Showcase 的 jquery 插件 所以,我的 CAML 查询有效。我有在 div 标签中调用的函数,因为我想将它显示为缩略图标题,但是,它似乎覆盖了页面上的所有内容并最后处理。

所以我所有的 div 标签和内容都没有了,它只在页面上写了函数的结果。

这是我的代码:

<script type="text/javascript">

`$(document).ready(function()'

{
    $("#showcase").awShowcase(
    {
        content_width:          700,
        content_height:         470,
        fit_to_parent:          false,
        auto:                   false,
        interval:               3000,
        continuous:             false,
        loading:                true,
        tooltip_width:          200,
        tooltip_icon_width:     32,
        tooltip_icon_height:    32,
        tooltip_offsetx:        18,
        tooltip_offsety:        0,
        arrows:                 true,
        buttons:                true,
        btn_numbers:            true,
        keybord_keys:           true,
        mousetrace:             false, /* Trace x and y coordinates for the mouse */
        pauseonover:            true,
        stoponclick:            true,
        transition:             'hslide', /* hslide/vslide/fade */
        transition_delay:       300,
        transition_speed:       500,
        show_caption:           'onhover', /* onload/onhover/show */
        thumbnails:             true,
        thumbnails_position:    'outside-last', /* outside-last/outside-first/inside-last/inside-first */
        thumbnails_direction:   'horizontal', /* vertical/horizontal */
        thumbnails_slidex:      0, /* 0 = auto / 1 = slide one thumbnail / 2 = slide two thumbnails / etc. */
        dynamic_height:         false, /* For dynamic height to work in webkit you need to set the width and height of images in the source. Usually works to only set the dimension of the first slide in the showcase. */
        speed_change:           false, /* Set to true to prevent users from swithing more then one slide at once. */
        viewline:               false /* If set to true content_width, thumbnails, transition and dynamic_height will be disabled. As for dynamic height you need to set the width and height of images in the source. */
    });
 });

</script>

<script type="text/javascript"> 
function GetNews(){
    /*Get News*/
    $().SPServices({
                 operation: "GetListItems",
                 webURL: 'http://weburl.com',
                 async: false,
                 listName: "Posts",
                 CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Primary' /><FieldRef Name='Pic' /><FieldRef Name='Short_x0020_Description' /></ViewFields>",
                 CAMLRowLimit: "10",
                CAMLQuery: "<Query><Where><Eq><FieldRef Name='Primary'/><Value Type='choice'>1</Value></Eq></Where></Query>",
                 completefunc: function (xData, Status) {
                 //alert("Status of XML message reaching Sharepoint webservice: " + Status);
                 //alert("Response from server: " + xData.responseText);

                       $(xData.responseXML).SPFilterNode("z:row").each(function () {
                           var name = ($(this).attr("ows_Title"));
                           document.write(name);
                           });
        }
    }); //Close getNews
}
</script> 


<body>
<div style="width: 700px; margin: auto;">
    <div id="showcase" class="showcase">
        <!-- Each child div in #showcase with the class .showcase-slide represents a slide. -->
        <div class="showcase-slide">
            <!-- Put the slide content in a div with the class .showcase-content. -->
            <div class="showcase-content">
                <!-- The image below needs to be from the variable above pictureUrl -->
                <img src="images/01.jpg" alt="01" />
            </div>
            <!-- Put the thumbnail content in a div with the class .showcase-thumbnail -->
            <div class="showcase-thumbnail">
                <!-- The image below needs to be from the variable above pictureUrl -->
                <img src="images/01.jpg" alt="01" width="140px" />
                <!-- The div below with the class .showcase-thumbnail-caption contains the thumbnail caption. This needs to be the variable 'name' from above -->
                <div class="showcase-thumbnail-caption"><div><script type="text/javascript">GetNews()</script></div></div>
                <!-- The div below with the class .showcase-thumbnail-cover is used for the thumbnails active state. -->
                <div class="showcase-thumbnail-cover"></div>
            </div>
            <!-- Put the caption content in a div with the class .showcase-caption. This needs to be the variable 'postDesc' from above -->
            <div class="showcase-caption">
                <h2>Be creative. Get Noticed!</h2>
            </div>
        </div>
    </div>

</div>

</body> 

最佳答案

好吧,它可能无法正常工作,因为您是直接将其写入文档而不是特定的 div

                       $(xData.responseXML).SPFilterNode("z:row").each(function () {
                       var name = ($(this).attr("ows_Title"));
                       document.write(name);//this line needs a fix maybe $('#divID').append('<h1>'+name+'<h1>') for eg
                       });

关于javascript - 在 DIV 中显示来自 SharePoint 的 CAML 查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13039493/

相关文章:

javascript - 如何将建议附加到文本输入?

javascript - jQuery onClick 执行

sharepoint - 使用 Caml 或 SPQuery 按标题字段从 sharepoint 列表中获取项目并忽略

sharepoint - Caml 查询 - 排序依据 - SharePoint 2013-CSOM

c# - SPQuery : Joining lists and where in the foreign list

javascript - 更改链接不适用于 jquery

sharepoint - 如何使用文本字段过滤 SharePoint 列表?

javascript - chop Sharepoint Online 列表中的 "Multiple lines of text"列

javascript - 使用 Javascript 动态构建 CAML

javascript - 如何在javascript中的一个函数中调用三个函数每个函数应该在第一个函数完成后调用