首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >到SPservices的JavaScript图库

到SPservices的JavaScript图库
EN

Stack Overflow用户
提问于 2016-05-23 21:43:13
回答 1查看 119关注 0票数 0

我找到了很好的JavaScript画廊here。我正在尝试使用SPServices从Sharepoint库中获取数据。但没起作用。我的代码有什么问题吗?

代码语言:javascript
复制
<script type="text/javascript" src="/Jscript/Jquery/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="/Jscript/SPServices/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript" src="/Script/js/fotorama.js"></script>
<link rel="stylesheet" href="/Script/js/fotorama.css" />


<script language="javascript" type="text/javascript">

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "2007PhotoAlbum",
    CAMLViewFields: "<ViewFields></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
	  
		
        var liHtml = "<div class='fotorama'><img src='" + "/photos/2007PhotoAlbum/" + $(this).attr("ows_PicFilename") +"'" + "></div>";
        $("#fotorama").append(liHtml);
      });
    }
  });
});


</script>
<div id="fotorama" data-width="700" data-ratio="700/467" data-max-width="100%"></div>
<script>
$('.fotorama').fotorama({
  width: 700,
  maxwidth: '100%',
  ratio: 16/9,
  allowfullscreen: true,
  nav: 'thumbs'
});
</script>

EN

回答 1

Stack Overflow用户

发布于 2016-05-31 21:29:57

在运行图库代码之前,SPServices调用可能不会完成。这使得SPServices看起来没有返回任何数据。您可以从检查SPServices是否返回数据开始。这段代码将把输出写入页面。

代码语言:javascript
复制
$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "2007PhotoAlbum",
    CAMLViewFields: "<ViewFields></ViewFields>",
    completefunc: function(xData, Status) {
        /***********************************Debugging*******************************/
            var out = $().SPServices.SPDebugXMLHttpResult({
            node: xData.responseXML
            });
            $("#debug").html("").append("<b>This is the output from the GetList operation:</b>" + out);
        /***************************************************************************/

      $(xData.responseXML).SPFilterNode("z:row").each(function() {


        var liHtml = "<div class='fotorama'><img src='" + "/photos/2007PhotoAlbum/" + $(this).attr("ows_PicFilename") +"'" + "></div>";
        $("#fotorama").append(liHtml);
      });
    }
  });

只要它返回数据,我建议您使用promises重写SPServices调用。然后在返回promise后运行.fotorama。Marc比较了使用和不使用promises here的情况。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37392664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档